22 lines
No EOL
431 B
Python
22 lines
No EOL
431 B
Python
import random as random_lib
|
|
import math
|
|
|
|
def random():
|
|
return random_lib.random()
|
|
|
|
def gaussian(mean=0.0, stddev=1.0):
|
|
while True:
|
|
x1 = (2.0 * random()) - 1.0
|
|
x2 = (2.0 * random()) - 1.0
|
|
w = (x1 * x1) + (x2 * x2)
|
|
if w < 1.0:
|
|
break
|
|
|
|
w = math.sqrt((-2.0 * math.log(w)) / w)
|
|
|
|
return mean + (x1 * w * stddev)
|
|
|
|
|
|
|
|
def randrange(min, max):
|
|
return min + (random() * (max - min)) |