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.
Feb 25th 2009, 10:35 PM
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).
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):
(Check my transcribing!) We will need to know what value the CDF takes at c: . 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:
(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 you pick the correct formula: