Generates random gaussian values.


example picture for random_gaussian()
1def setup():
2    py5.random_seed(42)
3    for y in range(100):
4        x = 15 * py5.random_gaussian()
5        py5.line(50, y, 50 + x, y)
example picture for random_gaussian()
 1def setup():
 2    py5.random_seed(42)
 3    py5.stroke(0)
 4    py5.background(204)
 5    py5.translate(py5.width/2, py5.width/2)
 7    distribution = [py5.random_gaussian(0, 15) for _ in range(360)]
 8    for d in distribution:
 9        py5.rotate(py5.TWO_PI/len(distribution))
10        py5.line(0, 0, abs(d), 0)


Generates random gaussian values. Each time the random_gaussian() function is called, it returns an unexpected float with a probability distribution set by the parameters. This function’s randomness can be influenced by random_seed().

If no parameters are passed to the function, returned values will have an average of 0 and a standard deviation of 1. Although there is theoretically no minimum or maximum value that this function might return, in practice returned values will be within plus or minus one standard deviation of the mean 68% of the time and within two standard devations 95% of the time. Values farther and farther from the mean become increasingly less likely.

If only one parameter is passed to the function, that parameter will be used as the average instead of 0. If two parameters are called, those values will be used as the average and standard deviation.

This function makes calls to numpy to generate the random values.


random_gaussian() -> float
random_gaussian(loc: float, /) -> float
random_gaussian(loc: float, scale: float, /) -> float


  • loc: float - average of randomly selected numbers

  • scale: float - standard deviation of randomly selected numbers

Updated on November 08, 2021 12:26:18pm UTC