{Global declarations}
CONST
   m = 100000000;     
   b = 31415821;
   m1 = 10000;

VAR
   RandNum : Integer4;
  


{Generate a pseudo-random number between 0 and 1.
RandNum should be seeded at start of each program. }

FUNCTION Random : Real;

FUNCTION Mult (p, q :Integer4) : Integer4;
Var 
   p1 , p0, q1, q0 : Integer4;
Begin
   p1 := p DIV m1;
   p0 := p MOD m1;
   q1 := q DIV m1;
   q0 := q MOD m1;
   Mult := (((p0*q1 + p1*q0) MOD m1) * m1 + p0*q0) MOD m;
End;


Begin
   RandNum := (Mult(RandNum,b) + 1) MOD m;
   Random := RandNum / m;
End;





{ Use the random number generator as follows:
 At beginning of program, read a value into RandNum
 (this is called seeding the random number generator).  
 Doing so will give the program a different sequence of random
 numbers for each different seed.
     Writeln('Seed the random number generator');
     Readln(RandNum);

 Each use of Random will produce a random number between 0 and
1.  If you need a random number between say 1 and MaxKey then
multiply the random number by 100 and truncate it.
   RandInt := Trunc(Random * MaxKey);
}

      