CHROMA
mainprogs
main
make_seeds.cc
Go to the documentation of this file.
1
/*
2
* This is rannyu as modified by A. Sokal 9/26/85.
3
* It is linear congruential with modulus m = 2**48, increment c = 1,
4
* and multiplier a = (2**36)*m1 + (2**24)*m2 + (2**12)*m3 + m4.
5
* The multiplier is stored in common (see subroutine setrn)
6
* and is set to a = 31167285 (recommended by Knuth, vol. 2,
7
* 2nd ed., p. 102).
8
*
9
* Multiplier is 31167285 = (2**24) + 3513*(2**12) + 821.
10
* Recommended by Knuth, vol. 2, 2nd ed., p. 102.
11
* (Generator is linear congruential with odd increment
12
* and maximal period, so seed is unrestricted: it can be
13
* either even or odd.)
14
*/
15
16
static
int
m
[4] = {0, 1, 3513, 821};
17
static
int
l
[4] = {0, 0, 0, 1};
18
19
float
rannyu
()
20
{
21
float
twom12 = 1/4096.0;
22
int
i
[4];
23
24
i
[0] =
l
[0]*
m
[3] +
l
[1]*
m
[2] +
l
[2]*
m
[1] +
l
[3]*
m
[0];
25
i
[1] =
l
[1]*
m
[3] +
l
[2]*
m
[2] +
l
[3]*
m
[1];
26
i
[2] =
l
[2]*
m
[3] +
l
[3]*
m
[2];
27
i
[3] =
l
[3]*
m
[3] + 1;
28
l
[3] =
i
[3] & 4095;
29
i
[2] =
i
[2] + (
i
[3] >> 12);
30
l
[2] =
i
[2] & 4095;
31
i
[1] =
i
[1] + (
i
[2] >> 12);
32
l
[1] =
i
[1] & 4095;
33
l
[0] = (
i
[0] + (
i
[1] >> 12)) >> 12;
34
return
twom12*((float)
l
[0] + twom12*((
float
)
l
[1] + twom12*((float)
l
[2] + twom12*((
float
)
l
[3]))));
35
}
36
37
/*! Seed has been set by default - this allows one to override it */
38
void
setrn
(
int
iseed[4])
39
{
40
int
i
;
41
for
(
i
=0;
i
< 4; ++
i
)
42
l
[
i
] = iseed[
i
];
43
}
44
45
/*! Recover the seed */
46
void
savern
(
int
iseed[4])
47
{
48
int
i
;
49
for
(
i
=0;
i
< 4; ++
i
)
50
iseed[
i
] =
l
[
i
];
51
}
52
53
54
#include <cstdio>
55
#include <iostream>
56
57
int
main
(
int
argc,
char
* argv[])
58
{
59
if
(argc != 3)
60
{
61
std::cerr <<
"Usage: "
<< argv[0] <<
": <num throw away> <num seeds>\n"
;
62
exit(1);
63
}
64
65
int
ndisc = atoi(argv[1]);
66
int
num = atoi(argv[2]);
67
68
for
(
int
n
=0;
n
< ndisc; ++
n
)
69
rannyu
();
70
71
for
(
int
n
=0;
n
< num; ++
n
)
72
{
73
float
f =
rannyu
();
74
75
int
iseed[4];
76
savern
(iseed);
77
printf(
"%d %d %d %d\n"
, iseed[1], iseed[2], iseed[3], iseed[0] & 2047);
78
}
79
}
i
unsigned i
Definition:
ldumul_w.cc:34
n
unsigned n
Definition:
ldumul_w.cc:36
main
int main(int argc, char *argv[])
Definition:
make_seeds.cc:57
setrn
void setrn(int iseed[4])
Definition:
make_seeds.cc:38
rannyu
float rannyu()
Definition:
make_seeds.cc:19
l
static int l[4]
Definition:
make_seeds.cc:17
m
static int m[4]
Definition:
make_seeds.cc:16
savern
void savern(int iseed[4])
Definition:
make_seeds.cc:46
Generated by
1.9.1