gaussdev (replaces TGaussDev)


The gaussdev function returns a 1-dimensional array of random numbers distributed according to a Gaussian probability density function. These values are known as "Gaussian Deviates". The larger the number of values created, the more perfectly they will approximate a Gaussian normal distribution.

Syntax

tbl = gaussdev( nCount )

tbl = gaussdev( nCount, nStdDev )

tbl = gaussdev( nCount, nStdDev, nMean )

bullet.gif    nCount is the number of Gaussian Deviates to create.

bullet.gif    nStdDev is the standard deviation. If omitted, it is set to 1.0.

bullet.gif    nMean is the mean value. If omitted, it is set to 0.0.

bullet.gif    tbl is the returned array containing nCount values.

bullet.gif    On failure, nil is returned.

Example

The following script creates 1 million Gaussian random deviates, creates a histogram of the values, and plots the histogram. The random values are not symmetrical about the middle since they are drawn from a random population. To make this script brief, the default histogram binning option, "Auto", is used. The auto method computes the minimum and maximum of the values created and selects the number of bins betwee, Since these values are not specified, the script retrieves the histogram binning values actually used and then uses them for making the plot.

y = gaussdev( 1000000 )

-- create 1 million random deviates

H = new_histogram()

-- create a Histogram object

h = H:Calc( y )

-- compute the histogram

nCount = H:GetBinCount()

-- separate the 3 parameters for clarity

nMin = H:GetMin()+H:GetBinWidth()/2

 

nStep = H:GetBinWidth()

 

x = series( nCount, nMin, nStep )

-- create a series for the histgram x axis

plot( x, h )

-- plot the histogram

H:delete()

 

Below is the result of running this script. The plot uses default labels as they were not specified in this plot function call.

Related Topics

Table and Array Functions, random, series, CStats class


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2023 Mirametrics, Inc. All Rights Reserved.