To draw a random number from a normal distribution, we use numpy.random.normal()
. This function takes three parameters, loc
(mean), scale
(standard deviation), and size
(output shape).
Here is an example code snippet that generates a single random number from a normal distribution with mean=0 and standard deviation=1.
main.py74 chars5 lines
This will output a single random number from a standard normal distribution.
If you want to generate multiple numbers, simply change the size
parameter. For example, to generate 10 random numbers from the same distribution, use:
main.py55 chars3 lines
This will output an array of ten random numbers.
gistlibby LogSnag