When grabbing Random().nextInt(int) integers for two entirely separate mechanics (e.g. attack rolls and superficial random animations), is there any reason to use separate Random() instances for each mechanic? For example, might it help ensure a more even dispersion of random values for each mechanic?
–
Similarly, in a continuing game where an even dispersion of random values is important, is there any reason to store a Random()’s instance or seed with saved game data — and pick up where it left off when the game is loaded — rather than creating a new instance each time?
For example, in a turn-based game where the player may be lucky or unlucky on each turn, is it possible that creating a new Random() instance on game load could bring about a situation where a player is abnormally lucky or unlucky?
–
(Note: When I say “creating a new instance”, I mean using just “Random random = new Random()”, with no seed specified.)
Thanks!
No. No reason. Use the same instance.
With some exceptions:
The issue with same-seeding is that the PRNG sequence will start the same (and thus be known or, usually more often, causes the same [colliding] sequence and “lack of randomness”). The quality of the randomness of the sequence, however is not affected.
As an aside: thankfully Java has a pretty good default Random constructor:
In JDK 6 it is implemented as:
(Of course, it’s possible to imagine/contrive a degenerate scenario with the above implementation as well…)
Happy coding.