summaryrefslogtreecommitdiff
path: root/ipl/procs/rng.icn
diff options
context:
space:
mode:
Diffstat (limited to 'ipl/procs/rng.icn')
-rw-r--r--ipl/procs/rng.icn42
1 files changed, 42 insertions, 0 deletions
diff --git a/ipl/procs/rng.icn b/ipl/procs/rng.icn
new file mode 100644
index 0000000..8e945c4
--- /dev/null
+++ b/ipl/procs/rng.icn
@@ -0,0 +1,42 @@
+############################################################################
+#
+# File: rng.icn
+#
+# Subject: Procedure to generate random numbers
+#
+# Author: Ralph E. Griswold
+#
+# Date: June 11, 1994
+#
+############################################################################
+#
+# This file is in the public domain.
+#
+############################################################################
+#
+# This procedure generates a sequence of numbers using the linear
+# congruence method. With appropriate parameters, the result is
+# a pseudo-random sequence. The default values produce the sequence
+# used in Icon.
+#
+############################################################################
+#
+# Requires: large integers
+#
+############################################################################
+#
+# See also: lcseval.icn
+#
+############################################################################
+
+procedure rng(a, c, m, x)
+
+ /a := 1103515245 # multiplicative constant
+ /c := 453816694 # additive constant
+ /m := 2 ^ 31 - 1 # modulus
+ /x := 0 # initial value
+
+ suspend x
+ suspend x := iand(a * |x + c, m)
+
+end