MODULE random; (*--------------------------------------------------------- File name: random.pm Author: MM Date: 5/18/05 Problem: This program limits the size of the chain so that we can work in a section of it. We define 'RightLimit' and work only with the cells to the left of that one. It then fills that section of the array with random numbers. RandomInt(configuration) is a standard function. Example of Execution: Line is: 2 0 4 3 3 9 9 0 5 9 7 5 5 5 Cycles: 1 MOD + 1 RandomInt *) (*---------------------------------------------------------- CONFIGURATION ----------------------------------------------------------*) CONST MAXCELLS=1024; (* MAXCELLS cells in one line *) CONFIGURATION chain[0..(MAXCELLS - 1)]; CONNECTION left: chain [i] -> chain[(i-1) MOD MAXCELLS]; right: chain[i] -> chain[(i+1) MOD MAXCELLS]; (*---------------------------------------------------------- VARIABLES ----------------------------------------------------------*) VAR L: chain OF INTEGER; (* Line always "L# *) RightLimit: INTEGER; MaxVal: INTEGER; (*---------------------------------------------------------- MAIN ----------------------------------------------------------*) BEGIN L := ID( chain ); RightLimit := 15; (*work limited to the first 15 cells*) MaxVal := 10; (* maximum value for random *) IF L < RightLimit THEN (* work only in selected first 15 cells *) L := RandomInt(chain ) MOD MaxVal; (* Put random numbers in L *) (*printing*) WriteString( " Line is: "); WriteInt( L , 2); WriteLn; END; (* IF *) END random.