make sure __rand_0_1 does not return 0.0
[fio.git] / lib / rand.h
index b99f618c000f108db5fb56adfc4bc0eaa00cad30..a95bd28b49041991abb8a1713ad80c9ef086742a 100644 (file)
@@ -104,6 +104,19 @@ static inline uint64_t __rand(struct frand_state *state)
                return __rand32(&state->state32);
 }
 
+static inline double __rand_0_1(struct frand_state *state)
+{
+       if (state->use64) {
+               uint64_t val = __rand64(&state->state64);
+
+               return (val + 1.0) / (FRAND64_MAX + 1.0);
+       } else {
+               uint32_t val = __rand32(&state->state32);
+
+               return (val + 1.0) / (FRAND32_MAX + 1.0);
+       }
+}
+
 extern void init_rand(struct frand_state *, int);
 extern void init_rand_seed(struct frand_state *, unsigned int seed, int);
 extern void __fill_random_buf(void *buf, unsigned int len, unsigned long seed);