random.gauss: range
Robert Kern
robert.kern at gmail.com
Fri Feb 26 22:56:55 CET 2010
On 2010-02-26 15:26 PM, pistacchio wrote:
> hi,
> i'm trying the random.gauss function. can anyone explain how to get a
> number between a given range?
You don't. The Gaussian distribution has infinite range. The best you can do
with the standard library is to keep sampling until you get a number inside your
desired range. If you aren't careful about your choice of parameters, this could
waste a lot of time.
> like, from 0 to 20 with an average of
> 10? and how to determine the "steep" of the curve? i've never studied
> it, so mu and sigma don't really tell me a thing.
Study it:
http://en.wikipedia.org/wiki/Normal_distribution
mu is the mean, the location of the central peak. sigma is the standard
deviation, which controls the width of the peak. Larger sigma means wider and
shorter peak.
You may want another distribution, like random.betavariate():
http://en.wikipedia.org/wiki/Beta_distribution
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list
mailing list