Gaussian pseudo-random numbers -- math issues

Michael Lew michaell at unimelb.edu.au
Wed Oct 22 20:14:54 EDT 2008


Dear Tim,

I have an extensive library of statistical maths routines. This handler and
function will get you going with your problem:

on mouseUp pMouseBtnNo
    put fld "MeanFld" into tmean
    put fld "stdevFld" into tstdev
    put fld "sample sizeFld" into n
    put fastNormalDeviates(n) into tdevs
    split tdevs by return --to make it into an array
    multiply tdevs by tstdev --to make the scale the stdev to the desired
value
    add tmean to tdevs --to obtain the desired mean
    combine tdevs with return
    put tdevs into fld "outputFld"
end mouseUp

function fastNormalDeviates howmany
    --returns random deviates from a normal distribution mean 0, stdev 1.
    --Fast algorithm simply averages many deviates from uniform
distributions.
    --Many times faster than Gasdev-based algorithms.
    --Values returned are return-delimited.
    if howmany is empty then put 1 into howmany
    repeat howmany
        repeat 20
            add random(10000) to tsum
        end repeat
        put (5000.5-(tsum/20))/645 & return after tvals
        put empty into tsum
    end repeat
    delete last char of tvals
    return tvals
end fastNormalDeviates

Regards,
Michael

-- 
Michael J Lew
Senior Lecturer
Department of Pharmacology
email: michaell at unimelb.edu.au
Website: http://www.pharmacology.unimelb.edu.au/statboss
phone: +61 3 8344 7812

> I'm interested an a modest statistics demonstration, but I can't
> figure out how do to the math myself.
> 
> I'd like to have a few lines of code that produces a sequence of
> numbers. (whole numbers would probably be okay). I'd like to specify
> the number of numbers generated. Let's call that Z.
> 
> I'd like also to specify the desired mean and standard deviation. I'd
> like the function (is this a function??) to work in such a way that
> if Z is large, the set of numbers generated, if graphed as a
> frequency distribution, would be normally distributed, i.e., Gaussian.
> 
> If Z is rather small, then the mean and standard deviation of the
> numbers produced will would only approximate the desired mean and
> standard deviation. Different runs would produce different actual
> means and standard deviations.
> 
> If Z is very small, like 3 or 4, the numbers will look almost random.




More information about the use-livecode mailing list