Merge branch 'master' of ssh://brick.kernel.dk/data/git/fio
[fio.git] / lib / rand.h
CommitLineData
1fbbf72e
JA
1#ifndef FIO_RAND_H
2#define FIO_RAND_H
3
4struct frand_state {
5 unsigned int s1, s2, s3;
6};
7
8extern struct frand_state __fio_rand_state;
9
10static inline unsigned int __rand(struct frand_state *state)
11{
12#define TAUSWORTHE(s,a,b,c,d) ((s&c)<<d) ^ (((s <<a) ^ s)>>b)
13
14 state->s1 = TAUSWORTHE(state->s1, 13, 19, 4294967294UL, 12);
15 state->s2 = TAUSWORTHE(state->s2, 2, 25, 4294967288UL, 4);
16 state->s3 = TAUSWORTHE(state->s3, 3, 11, 4294967280UL, 17);
17
18 return (state->s1 ^ state->s2 ^ state->s3);
19}
20
21extern void init_rand(struct frand_state *);
22
23#endif