MODULE TestMaths; (* ========================================================================= Exercise the Maths Module Generate a set of random numbers using both the .NET random function and the Maths random function. Calculate the respective totals, counts, means, variances and standard deviations. Author : Chris Burrows Created: May 2007 (c) 2007-2008 CFB Software http://www.cfbsoftware.com/gpcp ========================================================================= *) IMPORT CPmain, Maths, Out, Sys := "[mscorlib]System"; (* ==================================================================== *) PROCEDURE WriteResult(IN msg: ARRAY OF CHAR; r: REAL); BEGIN Out.String(msg); Out.Real(r, 10); Out.Ln() END WriteResult; (* ==================================================================== *) PROCEDURE WriteResults(IN r: ARRAY OF REAL); BEGIN WriteResult("Total = ", Maths.Sum(r)); WriteResult("Count = ", LEN(r)); WriteResult("Mean = ", Maths.Mean(r)); WriteResult("Variance = ", Maths.Variance(r)); WriteResult("StdDev = ", Maths.StdDev(r)) END WriteResults; (* ==================================================================== *) PROCEDURE Calculate(); CONST count = 1000; range = 10000; VAR i: INTEGER; reals: ARRAY count OF REAL; random1: Maths.Random; random2: Sys.Random; BEGIN Out.String('Maths.Random:'); Out.Ln(); random1 := Maths.InitRandom(); FOR i := 0 TO count - 1 DO reals[i] := random1.Next(range) END; WriteResults(reals); Out.Ln(); Out.String('Sys.Random:'); Out.Ln(); random2 := Sys.Random.init(314159); FOR i := 0 TO count - 1 DO reals[i] := random2.Next(range) END; WriteResults(reals) END Calculate; (* ==================================================================== *) BEGIN Calculate() END TestMaths.