Game Version number: 1.2.0.124
Modded?: (Yes/No) N/A
If modded, please list the mods: N/A
Issue Description:
So after another schizo inducing dilemma, a bit of trouble shooting and feedback on the official Discord... The seed value used by Math method is not working as intended in a default scenario. It appears to be utilizing a static value before the function OnGameStart in BaseGameMode entity.
As an example I started a new game instance in workbench 4 times, all 4 times before I call Math.Randomize(-1) it always returns the same values. After calling Math.Randomize(-1) it functions as expected. This behavior is no different in a dedicated server environment or client.
WORKBENCH START 1 SCRIPT : RandomInt(0, 680843)): 673030 SCRIPT : RandomFloat01(): 0.445692 Call Math.Randomize(-1); SCRIPT : RandomInt(0, 680843)): 351714 SCRIPT : RandomFloat01(): 0.348155 WORKBENCH START 2 SCRIPT : RandomInt(0, 680843)): 673030 SCRIPT : RandomFloat01(): 0.445692 Call Math.Randomize(-1); SCRIPT : RandomInt(0, 680843)): 554926 SCRIPT : RandomFloat01(): 0.142766 WORKBENCH START 3 SCRIPT : RandomInt(0, 680843)): 673030 SCRIPT : RandomFloat01(): 0.445692 Call Math.Randomize(-1); SCRIPT : RandomInt(0, 680843)): 345460 SCRIPT : RandomFloat01(): 0.636433 WORKBENCH START 4 SCRIPT : RandomInt(0, 680843)): 673030 SCRIPT : RandomFloat01(): 0.445692 Call Math.Randomize(-1); SCRIPT : RandomInt(0, 680843)): 177384 SCRIPT : RandomFloat01(): 0.727989
After discussing it on Discord NiiRoZz chimed in about not using the Math method and instead to use RandomGenerator because of other mods potentially setting a fixed seed and not resetting it. Ok sure, I can do that no problem. Except the issue is array.GetRandomIndex() also uses the math method so.. yeah...
Solutions
- Fix the initial seed for Math method
- Change array.GetRandomIndex to use RandomGenerator instead of Math.RandomInt
- Leave a note about the use cases of Math.Randomize and how Math.Randomize should be reset to -1 after desired use is done