kopia lustrzana https://github.com/peterhinch/micropython-samples
Fix to pseudorandom number generator
rodzic
aab5075bfe
commit
807f6bfe72
|
@ -8,13 +8,13 @@
|
|||
# successive calls to rando() will produce the required result.
|
||||
# Timing 109us (Pyboard 1.1), 191us (Pyboard lite), 1.264ms (ESP8266)
|
||||
|
||||
|
||||
def xorshift64star(modulo, seed = 0xf9ac6ba4):
|
||||
x = seed
|
||||
def func():
|
||||
nonlocal x
|
||||
x ^= x >> 12
|
||||
x ^= x << 25
|
||||
x ^= ((x << 25) & 0xffffffffffffffff) # modulo 2**64
|
||||
x ^= x >> 27
|
||||
x &= 0xffffffffffffffff
|
||||
return (x * 0x2545F4914F6CDD1D) % modulo
|
||||
return func
|
||||
|
|
Ładowanie…
Reference in New Issue