48 typedef uint32_t p00_seed160[p00_seed160_len];
51 uint32_t p00_xorshift(p00_seed160 * p00_s) {
55 register uint32_t
const p00_0 = ((*p00_s)[5]) % 5;
56 register uint32_t
const p00_4 = p00_0 == 0 ? 4 : p00_0-1;
57 register uint32_t
const p00_2 = (p00_0 == 4) ? 1 : ((p00_0 == 3) ? 0 : p00_0+2);
60 register uint32_t
const p00_x = (*p00_s)[p00_0];
61 register uint32_t
const p00_y = (*p00_s)[p00_2];
62 register uint32_t
const p00_v = (*p00_s)[p00_4];
64 register uint32_t t = (p00_x^(p00_x>>7));
65 t = (p00_v^(p00_v<<6))^(t^(t<<13));
71 return (2*p00_y + 1) * t;
126 #define P00_BIGPRIME \
127 UINT64_C(10007814641597694113), \
128 UINT64_C(10015183610531627897), \
129 UINT64_C(10089390291074425231), \
130 UINT64_C(10117275823191396191), \
131 UINT64_C(10215588060907623179), \
132 UINT64_C(10389441874873414061), \
133 UINT64_C(10602620510410479149), \
134 UINT64_C(10690793455755991027), \
135 UINT64_C(10793439684376201283), \
136 UINT64_C(10969167379420052431), \
137 UINT64_C(11050883422537956197), \
138 UINT64_C(11110712460003231287), \
139 UINT64_C(11342254921836171103), \
140 UINT64_C(11388752923558666351), \
141 UINT64_C(11682943258734137249), \
142 UINT64_C(11697622259988783581), \
143 UINT64_C(11731205802697935733), \
144 UINT64_C(11799524298339249581), \
145 UINT64_C(11862963432241722239), \
146 UINT64_C(11903172551239393097), \
147 UINT64_C(11937270107112816793), \
148 UINT64_C(11962673972948293321), \
149 UINT64_C(12001454206321043837), \
150 UINT64_C(12066567988703197129), \
151 UINT64_C(12090279337620046961), \
152 UINT64_C(12320220036580238077), \
153 UINT64_C(12409336420886496139), \
154 UINT64_C(12441355201341188273), \
155 UINT64_C(12444926949253327381), \
156 UINT64_C(12464345941324672183), \
157 UINT64_C(12469071720100075169), \
158 UINT64_C(12541090550165194183), \
159 UINT64_C(12558029109792848393), \
160 UINT64_C(12629045726855953273), \
161 UINT64_C(12845265184712635099), \
162 UINT64_C(12904165305535099733), \
163 UINT64_C(12949777725323667257), \
164 UINT64_C(13014679980528315931), \
165 UINT64_C(13027415158206533719), \
166 UINT64_C(13073256976558063279), \
167 UINT64_C(13153853421202095331), \
168 UINT64_C(13381351390611252151), \
169 UINT64_C(13825543164380321747), \
170 UINT64_C(13917403769616578911), \
171 UINT64_C(13929904570285153753), \
172 UINT64_C(14140216129016347127), \
173 UINT64_C(14184039880925065139), \
174 UINT64_C(14271570646513640671), \
175 UINT64_C(14446852824178510313), \
176 UINT64_C(14666997777683867003), \
177 UINT64_C(14692182605128454039), \
178 UINT64_C(14771388299183335229), \
179 UINT64_C(15059759696658839237), \
180 UINT64_C(15091316017205268437), \
181 UINT64_C(15180626055737690959), \
182 UINT64_C(15339437418814258573), \
183 UINT64_C(15601183704045111169), \
184 UINT64_C(15983170142123181797), \
185 UINT64_C(16545722488476290101), \
186 UINT64_C(16580005714519352107), \
187 UINT64_C(16589193612296178103), \
188 UINT64_C(16620171437104037921), \
189 UINT64_C(16713706803710883721), \
190 UINT64_C(16826711990149094791), \
191 UINT64_C(16886322755473635461), \
192 UINT64_C(16950140700365130619), \
193 UINT64_C(16952043704640877837), \
194 UINT64_C(17020386452131177189), \
195 UINT64_C(17020824347466355583), \
196 UINT64_C(17044414685455096133), \
197 UINT64_C(17089443963053420461), \
198 UINT64_C(17165479835541081871), \
199 UINT64_C(17185820514261086599), \
200 UINT64_C(17191892745505804273), \
201 UINT64_C(17613198595545138731), \
202 UINT64_C(17653178755564367203), \
203 UINT64_C(17653752776501147281), \
204 UINT64_C(17728444844615762171), \
205 UINT64_C(17744620187156425403), \
206 UINT64_C(17816722786105806973), \
207 UINT64_C(17831662963314755641), \
208 UINT64_C(17886004545482299117), \
209 UINT64_C(17920151933265509833), \
210 UINT64_C(17969552600607433963), \
211 UINT64_C(18066918898331824901), \
212 UINT64_C(18094173144238831753), \
213 UINT64_C(18134240252569387847), \
214 UINT64_C(18219113917191524677), \
215 UINT64_C(18298168206731166317), \
216 UINT64_C(18319234190200763803)
220 uint32_t p00_bitpack(
void const* p00_p) {
221 uintptr_t p00_u = (uintptr_t)p00_p;
222 #if UINTPTR_MAX == UINT32_MAX
228 p00_u >>= (
sizeof(uint32_t)*CHAR_BIT);
236 void p00_rand_init(
void* p00_p) {
241 uint32_t p00_0 = p00_bitpack(&p00_s);
243 uint32_t p00_1 = p00_bitpack(p00_p);
244 struct timespec p00_ts;
246 uint32_t p00_2 = p00_ts.tv_sec;
247 uint32_t p00_3 = p00_ts.tv_nsec;
248 #ifdef TIME_MONOTONIC
249 struct timespec p00_tm;
251 uint32_t p00_4 = p00_tm.tv_nsec;
253 uint32_t p00_4 = p00_bitpack(__func__);
256 uint32_t p00_ind = p00_0 ^ p00_1 ^ p00_2 ^ p00_3 ^ p00_4;
257 p00_seed160 p00_st = {
266 for (
unsigned p00_i = 0; p00_i < 32; ++p00_i) p00_xorshift(&p00_st);
270 for (
unsigned p00_j = 0; p00_j < 2; ++p00_j) {
271 for (
unsigned p00_i = 0; p00_i < p00_seed160_len; ++p00_i)
272 (*p00_s)[p00_j][p00_i] = p00_xorshift(&p00_st);
311 p99_call_once(&p00_loc->p00_flag, p00_rand_init, &p00_loc->p00_seed);
312 return &p00_loc->p00_seed;
316 uint64_t
const p00_bigprime[] = { P00_BIGPRIME };
340 uint64_t p99_rand(
register p99_seed * p00_seed) {
341 uint32_t p00_0 = p00_xorshift(&(*p00_seed)[0]);
342 uint64_t p00_1 = p00_xorshift(&(*p00_seed)[1]);
343 uint64_t p00_0r = p00_0 % p00_bigprime_len;
344 uint64_t p00_0d = p00_0 / p00_bigprime_len;
346 p00_1 *= p00_bigprime[p00_0r];
348 return (p00_0d ^ p00_1);
352 #define p99_rand(...) P99_CALL_DEFARG(p99_rand, 1, __VA_ARGS__)
353 #define p99_rand_defarg_0() (p99_seed_get())
372 double p99_drand(
register p99_seed * p00_seed) {
374 p00_s = (DBL_MANT_DIG > 64 ? 64 : DBL_MANT_DIG),
376 p00_m = (1 << p00_0),
378 double const p00_imax = 1.0 / (UINT64_C(1) << p00_s);
379 uint64_t p00_r = p99_rand(p00_seed);
380 double p00_1 = ((p00_r >> p00_0)^(p00_r & p00_m)) * p00_imax;
385 #define p99_drand(...) P99_CALL_DEFARG(p99_drand, 1, __VA_ARGS__)
386 #define p99_drand_defarg_0() (p99_seed_get())