| 624 | // sampler |
| 625 | |
| 626 | unsigned int random_u32(uint64_t *state) { |
| 627 | // xorshift rng: https://en.wikipedia.org/wiki/Xorshift#xorshift.2A |
| 628 | *state ^= *state >> 12; |
| 629 | *state ^= *state << 25; |
| 630 | *state ^= *state >> 27; |
| 631 | return (*state * 0x2545F4914F6CDD1Dull) >> 32; |
| 632 | } |
| 633 | float random_f32(uint64_t *state) { // random float32 in [0,1) |
| 634 | return (random_u32(state) >> 8) / 16777216.0f; |
| 635 | } |