Srand
Jump to navigation
Jump to search
srand( val )
- Initializes the random number generator with an explicit seed value.
- val
-
- The seed value.
The random number generator used by rnd()
is initialized with an unpredictable seed value when PICO-8 starts. You can reinitialize the generator with an explicit seed using srand()
.
This is mostly useful for testing random behaviors in your game with a known sequence. You can call srand()
before a call to rnd()
and get a predictable result.
Examples
print(rnd(20)) -- unpredictable, for example 3.837
print(rnd(20)) -- unpredictable, for example 19.089
srand(1)
print(rnd(20)) -- 7.081
print(rnd(20)) -- 1.989
print(rnd(20)) -- 16.593
srand(1)
print(rnd(20)) -- 7.081
print(rnd(20)) -- 1.989
print(rnd(20)) -- 16.593