| 1 | #include "rand.h" |
| 2 | |
| 3 | struct frand_state __fio_rand_state; |
| 4 | |
| 5 | static inline int __seed(unsigned int x, unsigned int m) |
| 6 | { |
| 7 | return (x < m) ? x + m : x; |
| 8 | } |
| 9 | |
| 10 | void init_rand(struct frand_state *state) |
| 11 | { |
| 12 | #define LCG(x) ((x) * 69069) /* super-duper LCG */ |
| 13 | |
| 14 | state->s1 = __seed(LCG((2^31) + (2^17) + (2^7)), 1); |
| 15 | state->s2 = __seed(LCG(state->s1), 7); |
| 16 | state->s3 = __seed(LCG(state->s2), 15); |
| 17 | |
| 18 | __rand(state); |
| 19 | __rand(state); |
| 20 | __rand(state); |
| 21 | __rand(state); |
| 22 | __rand(state); |
| 23 | __rand(state); |
| 24 | } |