tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
21
Task/Random-numbers/Modula-3/random-numbers.mod3
Normal file
21
Task/Random-numbers/Modula-3/random-numbers.mod3
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
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.
|
||||
Loading…
Add table
Add a link
Reference in a new issue