Getting a random number with a distribution function

Click For Summary

Discussion Overview

The discussion revolves around generating random numbers from an exponential distribution using a pseudo-random number generator (PRNG). Participants explore the relationship between the mean of the distribution, the cumulative distribution function (CDF), and the method for inverting the CDF to obtain random samples.

Discussion Character

  • Exploratory
  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • One participant asks how to use a PRNG to generate random numbers from an exponential distribution with a given mean (mu).
  • Another participant suggests the formula -(mu)*ln(1-rand()) as a potential solution.
  • A third participant emphasizes the need to understand the cumulative distribution function (CDF) and states that the formula provided is correct for inverting the CDF of an exponential distribution.
  • There is a clarification regarding the definition of rand(), with one participant noting that it is hypothetical and generates a number between 0 and 1, while another mentions that in some programming languages, rand() may return an integer.
  • One participant expresses confusion about the use of 'lambda' in relation to 'mu' in the context of the exponential distribution.
  • Another participant confirms that the suggested method is theoretically correct but warns about the practical issue of rand() potentially returning exactly 1, which would lead to a mathematical problem in the formula.

Areas of Agreement / Disagreement

Participants generally agree on the theoretical approach to generating random numbers from the exponential distribution using the CDF inversion method. However, there are discussions about the practical implications of using rand() in programming, indicating some uncertainty about its implementation.

Contextual Notes

There are unresolved questions regarding the definition of rand() in different programming contexts and the implications of its behavior on the mathematical validity of the proposed method.

Who May Find This Useful

This discussion may be useful for individuals interested in statistical programming, random number generation, and the application of probability distributions in computational contexts.

oneamp
Messages
222
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
5K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 11 ·
Replies
11
Views
4K
  • · Replies 1 ·
Replies
1
Views
1K