This game uses Unity’s built-in random module, which itself is an implementation Xorshift 128. Internally it maintains a list of 4 numbers, which are used to generate the next number in the sequence, and the first number is ejected, the last number is added to back of the list. Here is a sample implementation of what the game does:
def next_xorshift128(state):
"""
:input: tuple/list of 4 signed 32-bit ints: (s0, s1, s2, s3)
:return: next state as tuple of 4 signed 32-bit ints, next output (signed int)
"""
s0 = state[0] & 0xFFFFFFFF
s1 = state[1] & 0xFFFFFFFF
s2 = state[2] & 0xFFFFFFFF
s3 = state[3] & 0xFFFFFFFF
t = s0 ^ ((s0 << 11) & 0xFFFFFFFF)
s0 = s1
s1 = s2
s2 = s3
s3 = s3 ^ (s3 >> 19) ^ t ^ (t >> 8)
s3 &= 0xFFFFFFFF
def to_signed(x):
return x if x < 0x80000000 else x - 0x100000000
next_state = (to_signed(s0), to_signed(s1), to_signed(s2), to_signed(s3))
next_output = to_signed(s3)
return next_state, next_output
Now all that is not required knowledge for runners or strat-hunters. This is because we only care about what actions in the game reset or advance the RNG and how many times.
Here are the known things and the amount by which they shift the RNG (or don’t):
| Action | Shift |
|---|---|
| Drinking from a fountain | Unclear. For the palace fountain it seems to advance by 4 if the prince drinks immediately from it. |
| Breaking the purple orbs thing | An uncontrollable amount of time |
| Idle Animation | 1 |
| Dialogue | 0 |
| Dashing | 0 |
| Jumping | 0 |
| Wallrunning | 0 |
| Gripping a wall after a walljump | At least 1 per frame (uncontrollable) |
| Jumping off a pole with a yellow flash | 1 |
| Activating Vayu’s breath | 0 |
| Frontflip while Vayu’s breath is active | 1 |
| Backflip while Vayu’s breath is active | 0 |
Note - This is not an exhaustive list by any means. There are many many many other things that update the RNG, and will be added to the list in the future if it’s useful and predictable.
Here are the known things that reset the RNG to a specific value: