Main Page
Related Pages
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
libpolys
misc
sirandom.c
Go to the documentation of this file.
1
#include "
sirandom.h
"
2
3
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
4
/*
5
*
6
* A prime modulus multiplicative linear congruential
7
* generator (PMMLCG), or "Lehmer generator".
8
* Implementation directly derived from the article:
9
*
10
* S. K. Park and K. W. Miller
11
* Random Number Generators: Good Ones are Hard to Find
12
* CACM vol 31, #10. Oct. 1988. pp 1192-1201.
13
*
14
* Using the following multiplier and modulus, we obtain a
15
* generator which:
16
*
17
* 1) Has a full period: 1 to 2^31 - 2.
18
* 2) Is testably "random" (see the article).
19
* 3) Has a known implementation by E. L. Schrage.
20
*/
21
22
23
#define A 16807
/* A "good" multiplier */
24
#define M 2147483647
/* Modulus: 2^31 - 1 */
25
#define Q 127773
/* M / A */
26
#define R 2836
/* M % A */
27
28
29
int
siSeed
= 1;
30
31
int
siRandNext
(
int
r
)
32
{
33
r =
A
* (r %
Q
) -
R
* (r /
Q
);
34
35
if
( r < 0 )
36
r +=
M
;
37
38
return
( r );
39
}
40
41
int
siRand
()
42
{
43
siSeed
=
siRandNext
(
siSeed
);
44
return
siSeed
;
45
}
46
int
siRandPlus1
(
int
r
)
47
{
48
return
r+1;
49
}
sirandom.h
Q
#define Q
Definition:
sirandom.c:25
siRandPlus1
int siRandPlus1(int r)
Definition:
sirandom.c:46
M
#define M
Definition:
sirandom.c:24
r
const ring r
Definition:
syzextra.cc:208
siRandNext
int siRandNext(int r)
Definition:
sirandom.c:31
A
#define A
Definition:
sirandom.c:23
siSeed
int siSeed
Definition:
sirandom.c:29
R
#define R
Definition:
sirandom.c:26
siRand
int siRand()
Definition:
sirandom.c:41
Generated on Mon Mar 6 2017 11:17:30 by
doxygen 1.8.8
for
Singular debian-1:4.0.3-p3+ds-5~bpo8+1