Stephen Dunn's Homepage


-xkcd


There is an interesting paper which describes various techniques to reverse engineer psuedorandom number generators (PRNGs). You may download an implementation of one described algorithm written for Java here, or you can view the same (very short) source files individually:



partialState.java     random.java


Here is what compiling and running in your terminal should look like:


$ javac partialState.java random.java    # compile
$ java partialState                      # run
First number: 1675782518
Second number: -1508613918

The state is: 182606455011546

Predicted series: 395259385 -712260727 1455416184 901712159 270116689 1980282543 -1883941204 -694007715 -1322844696 652016178
Actual series: 395259385 -712260727 1455416184 901712159 270116689 1980282543 -1883941204 -694007715 -1322844696 652016178

Think of this as a reminder to re-seed your PRNG frequently when security matters.