Fix parser using uninitialized memory
[fio.git] / lib / rand.h
CommitLineData
1fbbf72e
JA
1#ifndef FIO_RAND_H
2#define FIO_RAND_H
3
2615cc4b
JA
4#define FRAND_MAX (-1U)
5
1fbbf72e
JA
6struct frand_state {
7 unsigned int s1, s2, s3;
8};
9
10extern struct frand_state __fio_rand_state;
11
12static inline unsigned int __rand(struct frand_state *state)
13{
14#define TAUSWORTHE(s,a,b,c,d) ((s&c)<<d) ^ (((s <<a) ^ s)>>b)
15
16 state->s1 = TAUSWORTHE(state->s1, 13, 19, 4294967294UL, 12);
17 state->s2 = TAUSWORTHE(state->s2, 2, 25, 4294967288UL, 4);
18 state->s3 = TAUSWORTHE(state->s3, 3, 11, 4294967280UL, 17);
19
20 return (state->s1 ^ state->s2 ^ state->s3);
21}
22
23extern void init_rand(struct frand_state *);
2615cc4b 24extern void init_rand_seed(struct frand_state *, unsigned int seed);
7d9fb455
JA
25extern void __fill_random_buf(void *buf, unsigned int len, unsigned long seed);
26extern unsigned long fill_random_buf(void *buf, unsigned int len);
1fbbf72e
JA
27
28#endif