Here's one opinion: I see having distinct RNG's as illuminating
rather than confusing, particularly if appropriately commented.
It seems too often an RNG is viewed like a system service - just
hook in if you want a random number. But this issue with the
GUI illuminates that if you have a path in your program that
may be non-deterministic - such as data communications, human
interaction, input size, etc - and if that path also uses the same RNG
as the rest of your otherwise deterministic experiment, inconsistency
will occur. Further, I've encountered people who seem blocked on the
concept of having multiple generators for multiple purposes. So
having more than one in the sample code could be useful in that
way, as well as preventing the issue Chris encountered.
On 8/19/2011 5:12 PM, Sean Luke wrote:
> On Aug 19, 2011, at 10:33 AM, Chris Wright wrote:
>> When running the example "Flockers" program without a GUI, the results
>> compared to a non-GUI version with the same seed seem to differ
>> significantly. More specifically, the positioning of the "dead" flockers
>> appears to be the same but those of the live flockers are vastly different
>> at the same number of iterations. Both give consistent, but different,
>> results each run.
> Took me a while to realize what was happening, but it's simple: the GUI version of Flockers
> uses the random number generator to produce the random colors of each flocker! If you change
> these lines in FlockersWithUI.
> new Color( 128 + state.random.nextInt(128),
> 128 + state.random.nextInt(128),
> 128 + state.random.nextInt(128)),
> Then the problem goes away. But of course the flockers are no longer pretty. So that brings up
> an interesting question: do we want to guarantee the same exact result on the GUI versus the
> command line even if the GUI version uses the random number generator? If this isn't a big deal
> (and it probably isn't) then no. But if it matters, then we'd probably need a separate RNG just
> for the GUI, which is entirely doable -- we could just build a MersenneTwister and use it, for
> example. Not a hard thing to add. But would an additional RNG be confusing?