Last Updated : 15 Jul, 2025
random module is used to generate random numbers in Python. Not actually random, rather this is used to generate pseudo-random numbers. That implies that these randomly generated numbers can be determined. gauss() is an inbuilt method of the random module. It is used to return a random floating point number with gaussian distribution.
Example:
Python
import random
mu = 100
sigma = 50
print(random.gauss(mu, sigma))
Output :
127.80261974806497
Explanation: This code generates and prints a random number from a Gaussian distribution with a mean (mu) of 100 and a standard deviation (sigma) of 50 using the random.gauss() function. The result will be a value close to 100 but can vary within a range due to the standard deviation.
SyntaxParametersrandom.gauss(mu, sigma)
We can generate the number multiple times and plot a graph to observe the gaussian distribution.
Python
import random
import matplotlib.pyplot as plt
# store the random numbers in a list
nums = []
mu = 100
sigma = 50
for i in range(100):
temp = random.gauss(mu, sigma)
nums.append(temp)
# plotting a graph
plt.plot(nums)
plt.show()
Output :
Gaussian Distribution PlotExplanation: This code generates 100 random numbers following a Gaussian distribution with a mean of 100 and a standard deviation of 50. It stores these numbers in a list and then plots the values using matplotlib to visualize the distribution.
2. Gaussian Distribution HistogramWe can create a histogram to observe the density of the gaussian distribution.
Python
import random
import matplotlib.pyplot as plt
# store the random numbers in a list
nums = []
mu = 100
sigma = 50
for i in range(10000):
temp = random.gauss(mu, sigma)
nums.append(temp)
# plotting a graph
plt.hist(nums, bins = 200)
plt.show()
Output :
Gaussian Distribution HistogramExplanation: This code generates 10,000 random numbers following a Gaussian distribution with a mean of 100 and a standard deviation of 50. It stores the numbers in a list and then plots a histogram using matplotlib to visualize the distribution with 200 bins.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4