Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Getting a random number with a distribution function

  1. Jan 28, 2014 #1
    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. jcsd
  3. Jan 28, 2014 #2
    -(mu)*ln(1-rand()) is that about right?
     
  4. Jan 29, 2014 #3

    Office_Shredder

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

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

    Stephen Tashi

    User Avatar
    Science Advisor

    What is definition of the function rand() in the programming language that you are using?
     
  6. Jan 29, 2014 #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
     
  7. Jan 29, 2014 #6

    Stephen Tashi

    User Avatar
    Science Advisor

    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).
     
  8. Jan 29, 2014 #7
    Thank you very much!
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Getting a random number with a distribution function
Loading...