22 lines
464 B
Plaintext
22 lines
464 B
Plaintext
MODULE Rand EXPORTS Main;
|
|
|
|
IMPORT Random;
|
|
FROM Math IMPORT log, cos, sqrt, Pi;
|
|
|
|
VAR rands: ARRAY [1..1000] OF LONGREAL;
|
|
|
|
(* Normal distribution. *)
|
|
PROCEDURE RandNorm(): LONGREAL =
|
|
BEGIN
|
|
WITH rand = NEW(Random.Default).init() DO
|
|
RETURN
|
|
sqrt(-2.0D0 * log(rand.longreal())) * cos(2.0D0 * Pi * rand.longreal());
|
|
END;
|
|
END RandNorm;
|
|
|
|
BEGIN
|
|
FOR i := FIRST(rands) TO LAST(rands) DO
|
|
rands[i] := 1.0D0 + 0.5D0 * RandNorm();
|
|
END;
|
|
END Rand.
|