blob: 8e945c4d39abaf89ea36e1afb902d39f096fda7a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
|