get a random number from a normal distribution with a mean of 0 and a standard deviation of 1 in python

You can use the random module combined with the numpy library to generate random numbers from a normal distribution with a mean of 0 and a standard deviation of 1 in Python. Here's some example code:

main.py
import random
import numpy as np

# Set the mean and standard deviation
mu, sigma = 0, 1

# Generate a random number from a normal distribution
rand_num = np.random.normal(mu, sigma)

# Alternatively, you can use the random module to get a random number from the standard normal distribution
rand_num_2 = random.gauss(mu, sigma)

# Print the random number
print(rand_num)
print(rand_num_2)
390 chars
16 lines

In this code, we first set the mean mu and standard deviation sigma of the normal distribution. We then use the numpy library to generate a random number from the normal distribution using the normal() function. Alternatively, we use the random module to generate a random number from the standard normal distribution using the gauss() function. Finally, we print the random numbers to the console.

gistlibby LogSnag