blob: b8d8f78d31fb13893d1ee879f84922ccc28cd5a5 [file] [log] [blame]
Jens Axboe1fbbf722010-03-25 23:03:18 +01001#include "rand.h"
2
3struct frand_state __fio_rand_state;
4
5static inline int __seed(unsigned int x, unsigned int m)
6{
7 return (x < m) ? x + m : x;
8}
9
10void 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}