## GB_FLIP

### May 25, 2010

The *Stanford GraphBase* of Donald Knuth provides a portable, high-quality random number generator called GB_FLIP. Based on the lagged fibonacci generator *a*_{n} = (*a*_{n-24} − *a*_{n-55}) mod *m*, GB_FLIP provides values on the range zero inclusive to 2^{31} exclusive, has a period of 2^{85} − 2^{30}, and the low-order bits of the generated numbers are just as random as the high-order bits. You can read Knuth’s original version of the program at http://tex.loria.fr/sgb/gb_flip.pdf.

Your task is to write your own version of GB_FLIP. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

Pages: 1 2

I’ve been trying to come up with a Python version, but the global variables are giving me the run around.

Here’s my Python version. It’s a fairly direct translation of Knuth’s C-code to Python.

[…] random number generators in past exercises, including Donald Knuth’s lagged-fibonacci generator that is used in the Standard Prelude. We also looked at cellular automata in a previous exercise. […]

Java implementation.