# Getting a random number with a distribution function

1. Jan 28, 2014

### oneamp

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

2. Jan 28, 2014

### oneamp

3. Jan 29, 2014

### Office_Shredder

Staff Emeritus
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. Jan 29, 2014

### Stephen Tashi

What is definition of the function rand() in the programming language that you are using?

5. Jan 29, 2014

### oneamp

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. Jan 29, 2014

### Stephen Tashi

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

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. Jan 29, 2014

### oneamp

Thank you very much!