| 65 | typedef uintptr_t* random_t; |
| 66 | |
| 67 | static uintptr_t pick(random_t r) { |
| 68 | uintptr_t x = *r; |
| 69 | #if (UINTPTR_MAX > UINT32_MAX) |
| 70 | // by Sebastiano Vigna, see: <http://xoshiro.di.unimi.it/splitmix64.c> |
| 71 | x ^= x >> 30; |
| 72 | x *= 0xbf58476d1ce4e5b9UL; |
| 73 | x ^= x >> 27; |
| 74 | x *= 0x94d049bb133111ebUL; |
| 75 | x ^= x >> 31; |
| 76 | #else |
| 77 | // by Chris Wellons, see: <https://nullprogram.com/blog/2018/07/31/> |
| 78 | x ^= x >> 16; |
| 79 | x *= 0x7feb352dUL; |
| 80 | x ^= x >> 15; |
| 81 | x *= 0x846ca68bUL; |
| 82 | x ^= x >> 16; |
| 83 | #endif |
| 84 | *r = x; |
| 85 | return x; |
| 86 | } |
| 87 | |
| 88 | static bool chance(size_t perc, random_t r) { |
| 89 | return (pick(r) % 100 <= perc); |