Random number not random during testing?

When using rand(#)+1, the output is always the same at build time. Then, if I restart in the test game with the restart command, it rolls a new random number… however, even this is the same each time in sequence. For example, with rand(16)+1, I always get a result of 8, and then after the first restart, a result of 14. How can I make the result actually random?

In debug builds, the RNG (random number generator) is initialized with a constant value, resulting in the same sequence of numbers. This is done to make debugging more deterministic.

You can try to manually initialize the RNG by calling the randomize() function (tadsgen.h provides it.) Just call it without parameters first. If that doesn’t help, try using the current game tick as a seed value:

randomize(RNG_ISAAC, getTime(GetTimeTicks));

See tads.org/t3doc/doc/sysman/tadsgen.htm

Note: you call randomize() once at game start. You don’t need to call it again after that.

Thank you! It appears that just calling the randomize() function with no params was enough to do the trick.

Keep in mind that if you (or a beta tester) find a bug that depends on the RNG (directly or indirectly), reproducing the bug in the exact same way again might not be possible, since the sequence of events that led to the bug will change. This is the reason why by default the RNG is initialized to the same sequence in debug builds.