Distributions

Random numbers can come in different distributions.

This refers to how frequently the various numbers are returned by your random function.

The basic functions (random() & uniform()) return uniform distributions - in other words, each possible number is equally likely to be returned.
If you call the function a large number of times, then you can expect each possible number to be returned about (but not exactly) the same number of times.
This is equivalent to the fact that if you flip a coin 1,000,000 times, you would expect to get roughly, but not exactly, 500,000 heads and 500,000 tails.

The following plot comes from calling int(random() * 100) 100,000 times. It shows how many times each of the possible values (from 0 to 99) was returned.

As expected, each number is returned roughly 1,000 times, with a moderate amount of variation, but no tendency to favor one number or any other real pattern.



Sometimes we would like a different distribution.

Another common distribution is the bell curve (or gaussian distribution). In this distribution, one small range of numbers is returned more frequently than others, with values further from the center of the distribution returned less and less frequently.

The function random.gauss(center, deviation) returns random numbers in a gaussian distribution.

The first argument (center) is the central number that the return values will be clustered around. The second argument (deviation) is the standard deviation of the distribution - this measures how broad the bell curve is; roughly 2/3 of all returned values will be within +/- deviation of the center value.

Example: a gaussian distribution lets you place objects randomly, but clustered about a center.

UniformGaussian