Mersenne Twister code Die Roller for VASSAL
Bill Thomson & Chuck Young
September 20, 2006
WGA SUMMARY
The original (and in most cases current) die roller inherent in the original VASL application and subsequent VASSAL engine has gained notoriety for generating streaks, clusters of results in a somewhat predictable pattern, and an inferred high frequency of extreme die rolls. Simple analysis of an overall distribution of a single batch of 10K 2d6 results has show a valid statistical distribution; however this is not necessarily true in the VASSAL game application which uses a large number of sets containing a small number of rolls.
As a result of this reputation, many players have modified their style of play during remote mode (PBEM/server) realizing that a normal distribution might not be generated. Others players have ceased using the inherent die roll altogether, substituting a third party die roller or relying on the honor system (each player rolls physical die at their location). The fortes of the inherent die roller are its ease of use and the fact that it is a common tool used by both players. These strengths are undermined if the results cannot be trusted.
The original Vassal die roller is based on the Java Pseudo Random Number Generator ("PRNG") which is similar to rand() in the C programming language. The latter has been considered notorious when used in Monte Carlo applications for years. If the similarity does indeed exist, the Java RNG is also suspect.
Solving both problems, the WGA VASSAL Team has configured a new die roller for use. Initially it is introduced as an additional set of buttons through use of a module based extension. Use of this button is recorded in the log with the text “Twister”. (The build file will require modification for each game module individually to create the corresponding extension.) Where WGA contributor control exists, a transition is being made to make it the only die roller. The new roller is based on Mersenne Twister code; and is identified by buttons with a yellow background.
The Mersenne Twister code has been fully validated through analysis using the
Diehard Test Suite®.
BACKGROUND REFERENCE:
- Several internet references exist which have established a consensus stating
rand() derived PRNGs are deficient when analyzed using a proven benchmarking
suite of software tools. (endnote 1)
- One of the dominant software tools is the Diehard Test Suite.
(endnote 2)
- Mersenne Twister has been tested by DIEHARD and has passed this evaluation.
It is ideal for Monte Carlo applications such as we have in the VASSAL dice
bot. Although not the ideal PRNG, it is in use by applications where randomness
is critical such as gambling sites. (endnote 3)
- C's rand() function fairs poorly when tested using DIEHARD despite a spirited
defense by many programmers. Serious gaming and gambling sites explicitly
avoid rand()'s use. rand() was originally developed for crytographic purposes
rather than Monte Carlo applications.
- Testing of the Vassal die roller is published on the vassal site. But this
Java PRNG code fails comprehensive testing via DIEHARD. Two different analyses
have yielded two different results(endnote 4).
The comprehensive testing using Diehard, an industry standard, favors the
Mersenne Twister code.
- A bullet point presentation on the analysis on the Java RNG had been published
by Four Delta. (endnote 5)This states “The
Sun RNG "uses a 48 bit seed but only 17 bits contribute to the LSB, producing
severe non-randomness and periodicy in the low order bits, despite extra code
to compensate for this effect“. It is unknown if VASSAL has implemented
modifications to utilize the higher order bits. Additionally, the Four Delta
presentation infers that rand() is the grandfather of the Java PRNG. Finally,
the Four Delta people used DIEHARD to test the Java PRNG, with highly discouraging
results. This is expected as rand() fails also.
- The Four Delta group compared the Mersenne Twister code to the native Java
PRNG in their presentation and found that it actually *runs faster*. (endnote
6)
- The ‘Twister’ die roller extension for the current VSQL3 module
is found on the VSQL module page of the VASSAL site. A “How to use Module
Extension’ guide is also found at this location. A VSQL3.1 will be posted
at this location to replace the current VSQL3.01 where Twister is the only
die roller. Twister will be the only die roller in the VSQL4 module currently
in Beta prior to its final release. WGA will approach the VASL module contributor
team, providing a VASL extension for consideration. (endnote
7)
CREDITS AND CONTACT INFORMATION
END NOTES
- http://www.google.com/search?hs=Ifw&hl=en&lr=&client=opera&rls=en&q=diehard+test+%7C+tested+random&btnG=Search
- http://www.stat.fsu.edu/pub/diehard/
- http://www.pierssen.com/arcview/upload/esoterica/randomizer.html
- http://www.vasl.org/vassal/RNG.html
- http://www.fourdelta.co.uk/ccs2005/ComputingRandomNumbers.pdf
- http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/JAVA/java.html
- http://www.vassalengine.org/community/index.php?option=com_vassal_modules&task=display&module_id=21&page=Files