Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sqrt, log, random, pi = math.sqrt, math.log, math.random, math.pi
- local function gauss(mi, sigmaSquared)
- local x1, x2, w, y1, y2
- repeat
- x1 = 2.0 * random() - 1.0
- x2 = 2.0 * random() - 1.0
- w = x1 * x1 + x2 * x2
- until w <= 1.0
- w = sqrt( (-2.0 * log( w ) ) / w )
- y1 = x1 * w
- y2 = x2 * w
- return y1*sigmaSquared+mi, y2*sigmaSquared+mi
- end
- -- returns 2 random values from range <0, 1>
- local y1, y2 = gauss(0.5, 1/(2*pi))
- print(y1, y2)
Advertisement
Add Comment
Please, Sign In to add comment