From 4c5946c6606abc87ba7e2bfc57a5030d19b6d4d5 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 26 Jul 2007 11:55:10 +0200 Subject: [PATCH] Fix verify random bytes filling Shawn Lewis reports: --- verify.c: fill_random_bytes() doesn't work as intended. drand48 on linux returns a double whose value is evenly distributed between 0.0 and 0.1. This is not the same as having an 8-byte value where each bit has the same chance of being 0 as it does of being 1. I'd fix this but it should probably be done in a cross-platformish way and I'm not quite sure how to do it. Maybe just use smaller randoms? Have an os_random_uint32? --- I just got rid of os_random_double() and used os_random_long(), truncating that to an unsigned integer. Signed-off-by: Jens Axboe --- os/os-freebsd.h | 7 ------- os/os-linux.h | 8 -------- os/os-solaris.h | 8 -------- verify.c | 4 ++-- 4 files changed, 2 insertions(+), 25 deletions(-) diff --git a/os/os-freebsd.h b/os/os-freebsd.h index 01c5ce91..ba2541a5 100644 --- a/os/os-freebsd.h +++ b/os/os-freebsd.h @@ -52,11 +52,4 @@ static inline long os_random_long(os_random_state_t *rs) return val; } -static inline double os_random_double(os_random_state_t *rs) -{ - double val; - - val = (double) rand_r(rs); - return val; -} #endif diff --git a/os/os-linux.h b/os/os-linux.h index f86ed322..1bf7e62a 100644 --- a/os/os-linux.h +++ b/os/os-linux.h @@ -199,14 +199,6 @@ static inline long os_random_long(os_random_state_t *rs) return val; } -static inline double os_random_double(os_random_state_t *rs) -{ - double val; - - drand48_r(rs, &val); - return val; -} - static inline int fio_lookup_raw(dev_t dev, int *majdev, int *mindev) { struct raw_config_request rq; diff --git a/os/os-solaris.h b/os/os-solaris.h index 898da18e..21d28e98 100644 --- a/os/os-solaris.h +++ b/os/os-solaris.h @@ -54,12 +54,4 @@ static inline long os_random_long(os_random_state_t *rs) return val; } -static inline double os_random_double(os_random_state_t *rs) -{ - double val; - - val = (double) rand_r(rs); - return val; -} - #endif diff --git a/verify.c b/verify.c index 32e7a041..794244a9 100644 --- a/verify.c +++ b/verify.c @@ -12,10 +12,10 @@ static void fill_random_bytes(struct thread_data *td, unsigned char *p, unsigned int len) { unsigned int todo; - double r; + int r; while (len) { - r = os_random_double(&td->verify_state); + r = os_random_long(&td->verify_state); /* * lrand48_r seems to be broken and only fill the bottom -- 2.25.1