Getting a random number with a distribution function

In summary, the conversation discusses the use of a mean mu and an exponential distribution function to generate random numbers. The formula -(mu)*ln(1-rand()) is proposed as a way to invert the CDF and obtain a random number from the distribution. The use and definition of rand() in programming languages is also mentioned. It is concluded that this is a correct way to generate random numbers, but caution must be taken with the possibility of rand() returning exactly 1.
  • #1
oneamp
219
0
I have a mean mu, and an exponential distribution function. How do I use a random number, generated with a PRNG, to get a random number from the distribution? I know this is a really basic question. Please help :)

Thanks
 
Physics news on Phys.org
  • #2
-(mu)*ln(1-rand()) is that about right?
 
  • #3
You need to know what the cumulative distribution is. If the CDF is F(y), then if you pick a number rand() uniformly at random from [0,1] you need to find the number y such F(y) = rand(). What you have written in your second post is the correct formula for inverting the CDF of an exponential distribution.
 
  • #4
oneamp said:
-(mu)*ln(1-rand()) is that about right?

What is definition of the function rand() in the programming language that you are using?
 
  • #5
rand() is just hypothetical; it generates a 'random' number between 0 and 1. Since what I've written in the second post is the correct formula for inverting the CDF (Thank you office shredder), is this a correct way that I can generate random numbers according to this distribution? I am confused that the web shows lambda where I show mu, for example...

Thank you
 
  • #6
oneamp said:
rand() is just hypothetical; it generates a 'random' number between 0 and 1.

If that's your definition of rand(), then you're OK. As defined in some programming languages rand() returns an integer value.

Since what I've written in the second post is the correct formula for inverting the CDF (Thank you office shredder), is this a correct way that I can generate random numbers according to this distribution?

Yes, it's the correct theoretical way. In an actual program, you must worry about whether rand() (the function implemented on the computer, not the theoretical uniform distribution) has a nonzero probability of returning exactly 1, which creates the problem ln(0).
 
  • #7
Thank you very much!
 

1. How do I generate a random number with a specific distribution function?

To generate a random number with a distribution function, you can use a random number generator that allows you to specify the distribution. Some programming languages, such as Python and R, have built-in functions for generating random numbers with various distributions. You can also create your own function using mathematical equations and algorithms.

2. What is a distribution function?

A distribution function is a mathematical function that describes the probability of a random variable taking on a certain value or falling within a certain range. It is used to model the distribution of a data set and can be used to generate random numbers with similar characteristics.

3. Can I customize the distribution of my random numbers?

Yes, you can customize the distribution of your random numbers by choosing a specific distribution function and adjusting the parameters. For example, you can generate numbers with a normal distribution by specifying the mean and standard deviation, or numbers with a uniform distribution by choosing a range of values.

4. How do I know if my random numbers have the desired distribution?

You can check if your random numbers have the desired distribution by visualizing the data in a histogram or by calculating summary statistics such as mean, standard deviation, and skewness. You can also use statistical tests, such as the Kolmogorov-Smirnov test, to determine if the data follows a specific distribution.

5. Are there limitations to generating random numbers with a distribution function?

Yes, there are limitations to generating random numbers with a distribution function. Some distributions may be more difficult to generate than others, and the quality of the random numbers produced may depend on the algorithm used. Additionally, the distribution may not accurately represent real-world data if the underlying assumptions are not met.

Similar threads

  • Set Theory, Logic, Probability, Statistics
Replies
30
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
5
Views
478
  • Set Theory, Logic, Probability, Statistics
Replies
6
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
11
Views
500
  • Set Theory, Logic, Probability, Statistics
Replies
7
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
7
Views
337
  • Set Theory, Logic, Probability, Statistics
Replies
7
Views
464
  • Set Theory, Logic, Probability, Statistics
Replies
6
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
2
Views
1K
Back
Top