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