previous up next print clean
Next: A simple shuffle Up: GENERATING RANDOM SEQUENCES Previous: GENERATING RANDOM SEQUENCES

Shuffling integers

Lehmer's Method for shuffling is the simplest, and is completely analysable.
1.
Multiply the current value, xj, by magic1, a constant.
2.
Reduce the result modulo magic2, another constant, and post in xj+1.
In FORTRAN this might look like:
      x(j) = MOD(x(j - 1)*magic1,magic2)
This scheme leads to a complete, shuffled set of the integers from 1 through (magic2-1) if certain constraints on magic1 and magic2 are met.
previous up next print clean
Next: A simple shuffle Up: GENERATING RANDOM SEQUENCES Previous: GENERATING RANDOM SEQUENCES
Stanford Exploration Project
11/18/1997