1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* |
---|
5 | * ABSTRACT: |
---|
6 | */ |
---|
7 | |
---|
8 | #include "config.h" |
---|
9 | #include <kernel/mod2.h> |
---|
10 | |
---|
11 | #ifdef HAVE_FACTORY |
---|
12 | #define SI_DONT_HAVE_GLOBAL_VARS |
---|
13 | # include <factory/factory.h> |
---|
14 | /* libfac version strings */ |
---|
15 | #ifdef HAVE_LIBFAC |
---|
16 | // extern const char * libfac_version; |
---|
17 | // extern const char * libfac_date; |
---|
18 | #endif // #ifdef HAVE_LIBFAC |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <coeffs/si_gmp.h> |
---|
22 | #include <omalloc/omalloc.h> |
---|
23 | |
---|
24 | /* init bins */ |
---|
25 | |
---|
26 | omBin char_ptr_bin = omGetSpecBin(sizeof(char*)); |
---|
27 | |
---|
28 | /*0 implementation*/ |
---|
29 | |
---|
30 | /*2 |
---|
31 | * the renice routine for very large jobs |
---|
32 | * works only on unix machines, |
---|
33 | * testet on : linux, HP 9.0 |
---|
34 | * |
---|
35 | *#include <sys/times.h> |
---|
36 | *#include <sys/resource.h> |
---|
37 | *extern "C" int setpriority(int,int,int); |
---|
38 | *void very_nice() |
---|
39 | *{ |
---|
40 | *#ifndef NO_SETPRIORITY |
---|
41 | * setpriority(PRIO_PROCESS,0,19); |
---|
42 | *#endif |
---|
43 | * sleep(10); |
---|
44 | *} |
---|
45 | */ |
---|
46 | |
---|
47 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
48 | /* |
---|
49 | * |
---|
50 | * A prime modulus multiplicative linear congruential |
---|
51 | * generator (PMMLCG), or "Lehmer generator". |
---|
52 | * Implementation directly derived from the article: |
---|
53 | * |
---|
54 | * S. K. Park and K. W. Miller |
---|
55 | * Random Number Generators: Good Ones are Hard to Find |
---|
56 | * CACM vol 31, #10. Oct. 1988. pp 1192-1201. |
---|
57 | * |
---|
58 | * Using the following multiplier and modulus, we obtain a |
---|
59 | * generator which: |
---|
60 | * |
---|
61 | * 1) Has a full period: 1 to 2^31 - 2. |
---|
62 | * 2) Is testably "random" (see the article). |
---|
63 | * 3) Has a known implementation by E. L. Schrage. |
---|
64 | */ |
---|
65 | |
---|
66 | |
---|
67 | #define A 16807 /* A "good" multiplier */ |
---|
68 | #define M 2147483647 /* Modulus: 2^31 - 1 */ |
---|
69 | #define Q 127773 /* M / A */ |
---|
70 | #define R 2836 /* M % A */ |
---|
71 | |
---|
72 | |
---|
73 | int siSeed = 1; |
---|
74 | |
---|
75 | |
---|
76 | int siRand() |
---|
77 | { |
---|
78 | siSeed = A * (siSeed % Q) - R * (siSeed / Q); |
---|
79 | |
---|
80 | if ( siSeed < 0 ) |
---|
81 | siSeed += M; |
---|
82 | |
---|
83 | return( siSeed ); |
---|
84 | } |
---|
85 | |
---|