
% LCG demonstrates how the line Y = 13 * X is folded back
% into the square [0,31] x [0,31] by the mod function,
% and maps each integer to another, in a perfect shuffle...
% except for 0, which doesn't move.
% 
clf

for i = 0 : 30
  x1 = 0;
  y1 = - i * 31;
  x2 = 31;
  y2 = 13*x2 - i * 31; 
  line ( [x1,x2], [y1, y2] );
  hold on
end

for x = 0 : 30
  y = mod ( 13 * x + 0, 31 );
  plot ( x, y, 'r*' )
  fprintf ( 1, '  (%d,%d)\n', x, y );
  hold on
end

axis ( [0, 31, 0, 31] )
axis square
grid
xlabel ( 'X(k)' )
ylabel ( 'X(k+1)' )
title ( 'X(k+1) = mod ( 13 * X(k) + 0, 31 )' )
