how to generate random numbers that satisfy certain distribution

Paul Rubin no.email at nospam.invalid
Sat Jan 23 17:10:10 EST 2010


Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> writes:
> The Box-Muller transform is reasonably simple, but you can't be serious 
> that it is simpler than adding twelve random numbers and subtracting six!

If you want a normal distribution, using the Box-Muller transform is
simpler because it spares you the complication of figuring out whether
the 12-trial binomial approximation is close enough to produce reliable
results for your specific application, which you obviously have to do if
you are using the approximation for anything serious.  It also involves
writing less code than that list comprehension, since it is already
implemented in the random module so you can just call it directly.



More information about the Python-list mailing list