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