Fandom

Pico-8 Wiki

Srand

162pages on
this wiki
Add New Page
Comments0 Share
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 Edit

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

See also Edit

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.