(* The Great Win32 Language Shootout http://dada.perl.it/shootout/

   contributed by Isaac Gouy (Modula2 novice)

   To build: xc =m random
   To run:   random 900000
*)

MODULE Random;
<* procinline + *>
<* ioverflow - *>
<* alignment="8" *>


(* Prefer unqualified procedures *)
FROM LanguageShootout IMPORT N;

FROM STextIO IMPORT WriteLn;
FROM SLongIO IMPORT WriteFixed;


CONST
   IM = 139968;
   IA = 3877;
   IC = 29573;

VAR
   n, last: INTEGER;
   result: LONGREAL;

PROCEDURE Gen_Random(max: LONGREAL): LONGREAL;
BEGIN
   last := (last*IA + IC) REM IM;
   RETURN max * LFLOAT(last) / LFLOAT(IM);
END Gen_Random;


BEGIN
   n := N();
   last := 42;

   WHILE n > 0 DO
      DEC(n);
      result := Gen_Random(100.0);
   END;  	

   WriteFixed(result,9,1); WriteLn;
END Random.