# -*- coding: utf-8 -*- """ Created 2022 Get random samples from a random number generator ('rng') and plot the density of a 'normal' or guassian random variable @author: neil """ import numpy as np import matplotlib.pyplot as plt nsamples = 1000000 # this is the number of random samples we want Q = np.random.default_rng().normal(0,1,nsamples) # guassian centeres on 0, sigma of 1 #Q = np.random.normal(0,1,nsamples) # a simpler call, if you don't care which random generator is used fig = plt.figure() # set up a plot window ax1 = fig.add_subplot(1,1,1) ax1.grid(True) ax1.hist(Q,bins=100) # this calls np.histogram to calculate the bins ax1.set_ylabel("Numbers in bins") ax1.set_xlabel("Values of gaussian random values") ax1.set_title("Filling bins with the Random Variables") plt.show()