Core Python / Random Numbers#
Under what circumstances should we explicitly set a fixed value for a random number generator?
Whenever the results need to be reproducible:
Software development: The system will have consistent behavior and output using a seed with random numbers.
Statistical analysis: By sharing the seed, others can replicate and verify the results.
Teaching simulation: Allows the students to see the same results (and possibly, odd results) for the material
Why is using the current date and time not an effective seed for a random number generator?
While a large number of possibilities exist for this value, it’s still relatively guessable as being able to be “brute-forced” by checking the numerous possibilities. Ideally, the seed needs to be generated by some sort of random event/measurement.
Search for “Monopoly Go airplane mode hack”. Why might the developers have allowed this hack to exist? Brainstorm possible ways to prevent.
By allowing the sequences to be repeatable, it may have been easier to test the game as the dice rolls were predictable. While we do not have access to Scopely’s code, we can make educated guesses about how “dice rolls” were implemented:
The system has generated a long sequence of random rolls/spins/cards. These are sent to the client (i.e., phone application) regularly. By having a consistent sequence for all players, any differences arising from randomness are removed/”evened”.
The system uses a consistent seed for the random numbers. That seed is part of the player’s configuration.
Several possibilities could prevent this hack:
Limit the time between contacts to the server. This raises the server load but minimizes the number of dice rolls that a player could perform.
Use a different seed every time the game is installed or started. This may cause repeatability concerns, but that could be mitigated with the use of a “test” environment or flag that forces a consistent seed to be used.