Sign in to follow this  
Followers 0
andybiochem

Random Number Generator - Gaussian Distribution

4 posts in this topic

#1 ·  Posted (edited)

Hi,

Here's a quick math function to generate random numbers based on the normal distribution (gaussian distribution).

This is the Box-Muller polar transformation FYI

#include <Array.au3>
#include <File.au3>

$Mean = 150
$StandardDeviation = 10.0

Dim $GaussianData[501]

For $i = 1 to (UBound($GaussianData) - 1)
    $GaussianData[$i] = _Random_Gaussian($Mean,$StandardDeviation,5)
Next

_ArrayDisplay($GaussianData)

Func _Random_Gaussian($nMean,$nSD,$iDP = 3)
;******************************************
; Box-Muller polar transform gaussian RND
;******************************************
; $iMean = The mean of the distribution
; $iSD = desired standard deviation
; $iDP = data precision (d.p.)
    Do
        $nX = ((2 * Random()) - 1)
        $nY = ((2 * Random()) - 1)
        $nR = ($nX^2) + ($nY^2)
    Until $nR < 1
    $nGaus = ($nX * (Sqrt((-2 * (Log($nR) / $nR)))))
    Return StringFormat("%." & $iDP & "f",($nGaus * $nSD) + $nMean)
EndFunc

By the way, how is Random() seeded in AutoIT? Is it standard time-based?...is there going to be a problem here with calling Random() in quick succession?

Edited by andybiochem

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!

Share this post


Link to post
Share on other sites



Hi,

Here's a quick math function to generate random numbers based on the normal distribution (gaussian distribution).

By the way, how is Random() seeded in AutoIT? Is it standard time-based?...is there going to be a problem here with calling Random() in quick succession?

AutoIt uses a special random number feature (read the included docs for more details) and initializes the random function at the beginning of an AutoIt session using the current time. To experiment, create a compiled script that just outputs the current time (in detail) and a random number to a Notepad session. Call this compiled script 10 times in a row and see what the output looks like.


David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Share this post


Link to post
Share on other sites

Just curious on how to obtain "true" random numbers.

Does anyone have an idea: if one substracts two reals of kind=4 from each other to be placed in a kind=8 variable. How random is the number that is obtained?


In the beginning there was nothing and then even that exploded - anonymous

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0