This applet provides a visual test for the java.util.Random class. It works very simply by repeatedly plotting the least significant bit of the java.util.Random.nextLong() method once for each point in the grid. As you can probably see by the horizontal stripes, this 'random' method exibits significant periodic behavoiour. Rather than looking like random static, the applet's display looks like a badly tuned-in television. All Java virtual machines that are available to me appear to exhibit the same problem. The nextInt method is also (approximately) half as seriously afflicted.
Observe that the applet displays a regular period - each fourth frame is the same. Random number generation algorithms which exhibit such behaviour in their low bits are less than ideal for generating integers without post-processing. The source code for the above applet is available for inspection here. I have formally submitted a bug report to Sun relating to this problem, complete with a proposal regarding how to remedy it.
Please direct any queries concering this page to Tim Tyler.
|