We can set seed to any value. But we can't reset it back so it would be random. Could you add this feature?
If you don't use srand, it gets called in the background with a random seed when you boot the cart, so all random calls are different each run. If you do use srand <seed>, all the next calls to rnd will come out of the same table, so you get the same results, in the same order, every time you run the cart.
If you want to for example use the srand seed to generate a map, but then want to go back to unpredictable things for other events (wind, hit chance etc), you need to give it a random seed.
Usually you call srand using the current time as the seed (or NULL, giving you random memory garbage) but with pico-8 that isn't possible.
You could try using a bunch of other stuff as the seed, like stat, btn, grabbing some memory locations, using the global T time variable, chaining rnd calls to it and so on. Do this constantly on the background and you get a fairly good chance you won't get two same results.
[Please log in to post a comment]