[35aab3] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
| 4 | /* |
---|
| 5 | * ABSTRACT: |
---|
| 6 | */ |
---|
| 7 | |
---|
[762407] | 8 | #include "config.h" |
---|
[599326] | 9 | #include <kernel/mod2.h> |
---|
[35aab3] | 10 | |
---|
| 11 | #ifdef HAVE_FACTORY |
---|
[24fd70] | 12 | #define SI_DONT_HAVE_GLOBAL_VARS |
---|
[b1dfaf] | 13 | # include <factory/factory.h> |
---|
[d3e630] | 14 | /* libfac version strings */ |
---|
[5348866] | 15 | #ifdef HAVE_LIBFAC |
---|
[81845eb] | 16 | // extern const char * libfac_version; |
---|
| 17 | // extern const char * libfac_date; |
---|
[5348866] | 18 | #endif // #ifdef HAVE_LIBFAC |
---|
[35aab3] | 19 | #endif |
---|
[d3e630] | 20 | |
---|
[cab375] | 21 | #include <coeffs/si_gmp.h> |
---|
[a5b80a] | 22 | #include <omalloc/omalloc.h> |
---|
[cab375] | 23 | |
---|
[a5b80a] | 24 | /* init bins */ |
---|
[35aab3] | 25 | |
---|
[a5b80a] | 26 | omBin char_ptr_bin = omGetSpecBin(sizeof(char*)); |
---|
[35aab3] | 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 | |
---|
[63105e5] | 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 */ |
---|
[35aab3] | 71 | |
---|
| 72 | |
---|
[ac8f221] | 73 | int siSeed = 1; |
---|
[35aab3] | 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 | |
---|