Jump to content

Random Normal Number generator


RobertKipling
 Share

Recommended Posts

To generate numbers on a bell curve, call this function with the mean and the standard deviation of the desired output. (This code was found elsewhere and adapted for AutoIt - use it if you find an application!)

Func randNorm($mean, $stddev)
    $x1=0
    $x2=0
    $w=2
    $y1=0
    $y2=0

    While ($w >= 1.0)
        $x1 = 2.0 * Random() - 1.0
        $x2 = 2.0 * Random() - 1.0
        $w = $x1 * $x1 + $x2 * $x2
    WEnd

    $w = Sqrt((-2.0 * Log($w)) / $w)
    $y1 = $x1 * $w
    $y2 = $x2 * $w
    Return $y1 * $stddev + $mean
EndFunc
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...