1 #ifndef FIO_RAND_H
2 #define FIO_RAND_H
3 
4 #define FRAND_MAX	(-1U)
5 
6 struct frand_state {
7 	unsigned int s1, s2, s3;
8 };
9 
frand_copy(struct frand_state * dst,struct frand_state * src)10 static inline void frand_copy(struct frand_state *dst,
11 			      struct frand_state *src)
12 {
13 	dst->s1 = src->s1;
14 	dst->s2 = src->s2;
15 	dst->s3 = src->s3;
16 }
17 
__rand(struct frand_state * state)18 static inline unsigned int __rand(struct frand_state *state)
19 {
20 #define TAUSWORTHE(s,a,b,c,d) ((s&c)<<d) ^ (((s <<a) ^ s)>>b)
21 
22 	state->s1 = TAUSWORTHE(state->s1, 13, 19, 4294967294UL, 12);
23 	state->s2 = TAUSWORTHE(state->s2, 2, 25, 4294967288UL, 4);
24 	state->s3 = TAUSWORTHE(state->s3, 3, 11, 4294967280UL, 17);
25 
26 	return (state->s1 ^ state->s2 ^ state->s3);
27 }
28 
29 extern void init_rand(struct frand_state *);
30 extern void init_rand_seed(struct frand_state *, unsigned int seed);
31 extern void __fill_random_buf(void *buf, unsigned int len, unsigned long seed);
32 extern unsigned long fill_random_buf(struct frand_state *, void *buf, unsigned int len);
33 extern void __fill_random_buf_percentage(unsigned long, void *, unsigned int, unsigned int, unsigned int, char *, unsigned int);
34 extern unsigned long fill_random_buf_percentage(struct frand_state *, void *, unsigned int, unsigned int, unsigned int, char *, unsigned int);
35 extern void fill_pattern(void *p, unsigned int len, char *pattern, unsigned int pattern_bytes);
36 
37 #endif
38