| 1 |
|
| #include "random.h" |
| 2 |
|
| #include <time.h> |
| 3 |
|
| |
| 4 |
|
| static uint64_t seed; |
| 5 |
|
| static bool enabled = true; |
| 6 |
|
| |
| 7 |
483217 |
| uint8_t GB_random(void) |
| 8 |
|
| { |
| 9 |
483217 |
▶ | if (!enabled) return 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!enabled) return 0; |
0 |
483217 |
483217 |
|
| 10 |
|
| |
| 11 |
483217 |
| seed *= 0x27BB2EE687B0B0FDL; |
| 12 |
483217 |
| seed += 0xB504F32D; |
| 13 |
483217 |
| return seed >> 56; |
| 14 |
|
| } |
| 15 |
|
| |
| 16 |
0 |
| uint32_t GB_random32(void) |
| 17 |
|
| { |
| 18 |
0 |
| GB_random(); |
| 19 |
0 |
| return seed >> 32; |
| 20 |
|
| } |
| 21 |
|
| |
| 22 |
0 |
| void GB_random_seed(uint64_t new_seed) |
| 23 |
|
| { |
| 24 |
0 |
| seed = new_seed; |
| 25 |
0 |
| } |
| 26 |
|
| |
| 27 |
0 |
| void GB_random_set_enabled(bool enable) |
| 28 |
|
| { |
| 29 |
0 |
| enabled = enable; |
| 30 |
0 |
| } |
| 31 |
|
| |
| 32 |
8 |
| static void __attribute__((constructor)) init_seed(void) |
| 33 |
|
| { |
| 34 |
8 |
| seed = time(NULL); |
| 35 |
520 |
▶ | for (unsigned i = 64; i--;) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (unsigned i = 64; i--;) { |
512 |
8 |
520 |
|
| 36 |
512 |
| GB_random(); |
| 37 |
|
| } |
| 38 |
8 |
| } |