def random_normal ( ): #*****************************************************************************80 # ## random_normal() tests generation of random normal values. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 30 January 2025 # # Author: # # John Burkardt # import matplotlib.pyplot as plt import numpy as np print ( '' ) print ( 'normal_test():' ) print ( ' Generate normal random values with np.random.normal().' ) for i in range ( 0, 3 ): if ( i == 1 ): seed = 987654321 else: seed = 123456789 np.random.seed ( seed ) n = 10000 r = np.random.normal ( size = n ) mx = np.max ( r ) mn = np.min ( r ) mu = np.mean ( r ) sg = np.std ( r ) vr = np.var ( r ) print ( '' ) print ( ' Seed = ', seed ) print ( ' Values = ', n ) print ( ' Minimum = ', mn ) print ( ' Mean = ', mu ) print ( ' Maximum = ', mx ) print ( ' STD = ', sg ) print ( ' Variance = ', vr ) # # Make a histogram of last set of results. # plt.hist ( r, bins = 20, rwidth = 0.95, density = True ) plt.grid ( True ) plt.xlabel ( '<-- Value -->' ) plt.ylabel ( '<-- Frequency -->' ) plt.title ( 'Normal random values from np.random.normal()' ) filename = 'random_normal.png' plt.savefig ( filename ) print ( '' ) print ( ' Graphics saved as "' + filename + '"' ) plt.show ( ) plt.close ( ) return if ( __name__ == "__main__" ): random_normal ( )