| 1 | module wyrand |
| 2 | |
| 3 | fn C._wymix(u64, u64) u64 |
| 4 | |
| 5 | // free should be called when the generator is no longer needed. |
| 6 | // WyRandRNG contains no heap-allocated fields, so this is a no-op. |
| 7 | @[unsafe] |
| 8 | pub fn (mut rng WyRandRNG) free() { |
| 9 | } |
| 10 | |
| 11 | // u64 returns a pseudorandom 64bit int in range `[0, 2⁶⁴)`. |
| 12 | @[ignore_overflow; inline] |
| 13 | pub fn (mut rng WyRandRNG) u64() u64 { |
| 14 | unsafe { |
| 15 | mut seed1 := rng.state |
| 16 | seed1 += wyp0 |
| 17 | rng.state = seed1 |
| 18 | return C._wymix(seed1 ^ wyp1, seed1) |
| 19 | } |
| 20 | return 0 |
| 21 | } |
| 22 | |