Glulx randomness and "undo"


#1

In a Glulx game, when a player types a command whose response involves some RNG, and then types UNDO followed by the same command, I’m wondering how that’s handled, and if it is interpreter-dependent.

Something like this, where the color is chosen randomly:

>SHAKE BOTTLE
The fluid turns green.

>UNDO
[Previous turn undone.]

>SHAKE BOTTLE
The fluid turns pink.

The Windows Inform 7 interpreter seems to allow different RNG after undoing. Is that the case for all interpreters?


(David Kinder) #2

Yes, that’s right. The Glulx specification mentions this in section 1.8.5: the internal state of the random number generate is not part of the saved game state, so is not affected by a restart, restore, or restoreundo operation.


(matt w) #3

If it’s important to you that this not happen, I think you can avoid it with Procedural Randomness by Aaron Reed–start by choosing a random seed, and then use procedurally random numbers for everything that otherwise requires randomness–I’m guessing that the state of the procedurally random number generator is part of the saved game state and would be affected by restart/restore/undo.


#4

Or my Xorshift extension. It’s simpler to integrate. It also uses very strong pseudo-random numbers, but I’m not sure what algorithm Aaron’s extension uses.


#5

How does the Procedural Randomness extension differ from Inform’s built-in seed the random number generator function?


#6

The built in function uses the interpreter’s own random implementation. It won’t be consistent across interpreters, and it may not be reliable.

Both extensions provide their own implementations so they will behave identically across all interpreters. Aaron’s extension gives separate phrases so that you need to change your code to use it, but it also makes it easy to have some procedural randomness, and some true randomness. My extension intercepts calls to the built in random functions so all randomness can be controlled. Both have their place, depending on what you want to do.


#7

Another way to avoid this happening would be to silently generate a bunch of random outcomes at the start of the game and refer to them as needed, maybe.