Sign in to follow this  
Followers 0
RobertKipling

Random Normal Number generator

2 posts in this topic

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

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