Results 1 to 2 of 2

Math Help - Random Number Generation

  1. #1
    Newbie
    Joined
    May 2008
    Posts
    18

    Random Number Generation

    I am trying to generate random numbers with the the constraint that the maximum value is 40 and the most likely value is around 40% of the maximum value. Are there any distributions (lognormal??) that would suit this requirement? If I assumed lognormal distribution, how would I generate this numbers with the constraint mentioned.Thanks a lot.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Member
    Joined
    Jul 2008
    Posts
    138
    Did you want continuous or discrete? I'll assume continuous since you mentioned the lognormal.

    No lognormal won't cut it (technically) because theoretically you can get any positive number (including larger that 40).

    An easy(ish) one would be triangular shaped. See Triangular distribution - Wikipedia, the free encyclopedia.

    In your case, a=0, b=40, and c=40% of 40 = 16. For what follows, I'll stick in the values for a and b, but leave c as c.

    To randomly generate this take the cumulative distribution function and compute it's inverse function (set expression = to y and solve for x). Then use the rand function (matlab, C, etc.), stick it into the function you just created and voila.

    CDF (from wikipedia): 0\leq x \leq c:\: \frac{x^2}{40c}
    c\leq x \leq 40:\: 1-\frac{(40-x)^2}{40(40-c)}

    (Check my transcribing!) We will need to know what value the CDF takes at c:
     CDF(c) = \frac{(c)^2}{40c} = \frac{c}{40}. This will be the where the equivalent split occurs for the inverse function. Note that the domain for the inverse function is [0,1] (CDF's always map some domain to [0,1] so the inverse does the opposite).

    To inverse this function, just invert each piece (set the expression = to y and then solve for x. You get:
    0 \leq  y \leq \frac{c}{40}:\: \sqrt{40cy}
    \frac{c}{40} \leq  y \leq 1:\: 40-\sqrt{40}\sqrt{(c-40)y-c+40}
    (Check my algebra)

    So now, to get your random number generator do the following. Produce a uniform random number from 0 to 1 (use rand for most languages that I know of). That number is y. Based on whether y is bigger or smaller than \frac{c}{40} you pick the correct formula:
    0 \leq  y \leq \frac{c}{40}:\: \sqrt{40cy}
    \frac{c}{40} \leq  y \leq 1:\: 40-\sqrt{40}\sqrt{(c-40)y-c+40}
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Random Number Generation Question
    Posted in the Advanced Statistics Forum
    Replies: 0
    Last Post: April 16th 2011, 02:25 PM
  2. Random Number Generation 1-100 odds
    Posted in the Statistics Forum
    Replies: 4
    Last Post: January 30th 2011, 12:01 PM
  3. Random Number Generation
    Posted in the Advanced Statistics Forum
    Replies: 1
    Last Post: April 29th 2009, 12:13 AM
  4. Random Number Generation
    Posted in the Advanced Statistics Forum
    Replies: 2
    Last Post: April 25th 2009, 03:59 PM
  5. MATLAB - Random Number Generation
    Posted in the Math Software Forum
    Replies: 4
    Last Post: February 18th 2009, 06:03 AM

Search Tags


/mathhelpforum @mathhelpforum