Fix to pseudorandom number generator

pull/7/head
Peter Hinch 2016-12-19 08:12:12 +00:00
rodzic aab5075bfe
commit 807f6bfe72
1 zmienionych plików z 2 dodań i 2 usunięć

Wyświetl plik

@ -8,13 +8,13 @@
# successive calls to rando() will produce the required result. # successive calls to rando() will produce the required result.
# Timing 109us (Pyboard 1.1), 191us (Pyboard lite), 1.264ms (ESP8266) # Timing 109us (Pyboard 1.1), 191us (Pyboard lite), 1.264ms (ESP8266)
def xorshift64star(modulo, seed = 0xf9ac6ba4): def xorshift64star(modulo, seed = 0xf9ac6ba4):
x = seed x = seed
def func(): def func():
nonlocal x nonlocal x
x ^= x >> 12 x ^= x >> 12
x ^= x << 25 x ^= ((x << 25) & 0xffffffffffffffff) # modulo 2**64
x ^= x >> 27 x ^= x >> 27
x &= 0xffffffffffffffff
return (x * 0x2545F4914F6CDD1D) % modulo return (x * 0x2545F4914F6CDD1D) % modulo
return func return func