Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RNG in TP is a floating point value (double) that is returned by using three 32-bit integers to function as the seed. The game seeds these three values at boot with 100, 100, 100 and it is then re-seeded on every subsequent call to the RNG function.
- Here's the function code:
- double cM_rnd() {
- double RNG_val;
- // these variable definitions are defined outside the function
- RNG0 = (RNG0 * 171) % 30269;
- RNG1 = (RNG1 * 172) % 30307;
- RNG2 = (RNG2 * 170) % 30323;
- RNG_val = fmod((double)((float)((double)CONCAT44(0x43300000,RNG2 ^ 0x80000000) - 0x4330000080000000) / 30323.0f +
- (float)((double)CONCAT44(0x43300000,RNG0 ^ 0x80000000) - 0x4330000080000000) / 30269.0f +
- (float)((double)CONCAT44(0x43300000,RNG1 ^ 0x80000000) - 0x4330000080000000) / 30307.0f),1.0f);
- return (double)ABS((float)RNG_val);
- }
- (The CONCAT44 is pseudocode generated by Ghidra that basically means concatenate the 2 float values together.)
- (The ABS takes the floating point absolute value before returning the value.)
- So with the initial seed 100,100,100 the new seed after running through one time will be 17100, 17200, 17000 and the resulting RNG value will be 0.6930906772613525 (hex: 3fe62dcc80000000).
- Interestingly, the algorithm here for calculating the final RNG value will always return a normalized value between 0.0 and 1.0. This value is then typically multiplied against another value which is changed on a case by case basis depending on the calling function.
- Here is a small RNG simulator program if you'd like to mess around with the seeding to see what values are returned: https://github.com/Pheenoh/tp-rng-simulator
Add Comment
Please, Sign In to add comment