Log In  

We can set seed to any value. But we can't reset it back so it would be random. Could you add this feature?

P#13791 2015-09-07 15:05 ( Edited 2015-09-08 22:13)

Not sure I understand?

it's random.

you can seed to control (or not) the values. they are still random.

the seed is so that, for example, you can use the same set of random values if need arises.

or...what do you want exactly?

P#13792 2015-09-07 16:22 ( Edited 2015-09-07 20:27)

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.

P#13794 2015-09-07 17:04 ( Edited 2015-09-07 21:04)
2

I ran into this problem and came up with a quick solution.

1) Store rand() into a global var trand.
2) Set srand() to a fixed number.
3) After running deterministic section, set srand(trand).

P#13800 2015-09-07 18:31 ( Edited 2015-09-07 22:31)

Your best source of entropy for a 'random' number to seed with will be player btn() presses.

P#13814 2015-09-08 03:08 ( Edited 2015-09-08 07:08)
1

I use innomin's method (to avoid providing an extra api function); the seed is random on cart boot for this reason, and is based on mysterious system-specific state and the phase of the moon.

P#13877 2015-09-08 18:13 ( Edited 2015-09-08 22:13)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 11:18:38 | 0.006s | Q:16