Gaussian pseudo-random numbers -- math issues

Mark Smith lists at futilism.com
Thu Oct 23 07:16:31 EDT 2008


Correction, I messed up with last night's version, so here's a  
correct one.


function polarBoxMuller pLength, pMean, pStd
    put 2 ^ 32 -1 into tMax
    repeat plength div 2
       repeat
          put (random(tMax) / tMax) * 2 - 1 into x
          put (random(tMax) / tMax) * 2 - 1 into y
          put x * x + y * y into r
          if r <> 0 and r <= 1 then exit repeat
       end repeat

       put sqrt( -2 * ln(r) / r) into d
       put pMean + (x * d) * pStd & comma after tList
       put pMean + (y * d) * pStd & comma after tList
    end repeat
    return char 1 to -2 of tList
end polarBoxMuller

Best,

Mark



More information about the use-livecode mailing list