Random numbers: Difference between revisions

Content added Content deleted
(added common lisp)
(Modula-3)
Line 236: Line 236:
append arr c
append arr c
)
)

=={{header|Modula-3}}==
Based on the C version.

<pre>
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.
</pre>


=={{header|OCaml}}==
=={{header|OCaml}}==