monome / crow

Crow speaks and listens and remembers bits of text. A scriptable USB-CV-II machine
GNU General Public License v3.0
162 stars 34 forks source link

add seeded random option #442

Closed trentgill closed 2 years ago

trentgill commented 2 years ago

previously we overwrote the built-in random function in Lua with the true RNG in the STM32.

this just aliases 'normal' (pseudo) RNG with a leading s (for seeded).

usage:

-- print some seeded random numbers
print(math.srandom()) --> 0.690001
print(math.srandom()) --> 0.5054184

-- reset crow
^^r

-- printing srandom again will produce the same sequence
print(math.srandom()) --> 0.690001
print(math.srandom()) --> 0.5054184

-- you can seed the PRNG yourself
math.srandomseed(314)
print(math.srandom()) --> 0.7310537
-- re-seeding to the same number always produces the same sequence
math.srandomseed(314)
print(math.srandom()) --> 0.7310537