Getting a random number with a distribution function

Click For Summary
To generate a random number from an exponential distribution using a PRNG, the formula -(mu)*ln(1-rand()) is correct for inverting the cumulative distribution function (CDF). The function rand() should generate a uniform random number between 0 and 1. It's important to ensure that the implementation of rand() does not return exactly 1, as this would lead to an undefined value in the logarithm. The discussion clarifies that while mu is used in the formula, some sources may refer to lambda, which can cause confusion. This approach is theoretically sound for generating random numbers according to the specified distribution.
oneamp
Messages
219
Reaction score
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
-(mu)*ln(1-rand()) is that about right?
 
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.
 
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?
 
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
 
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).
 
Thank you very much!
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 30 ·
2
Replies
30
Views
4K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K