Move version logging
[fio.git] / lib / rand.c
index cecc4c21ea90a28775f6e187a24c52429ab4f2f5..06812823994d45cfe744351095af015d5858fbae 100644 (file)
@@ -34,6 +34,7 @@
 */
 
 #include "rand.h"
+#include "../hash.h"
 
 struct frand_state __fio_rand_state;
 
@@ -57,3 +58,26 @@ void init_rand(struct frand_state *state)
        __rand(state);
        __rand(state);
 }
+
+void __fill_random_buf(void *buf, unsigned int len, unsigned long seed)
+{
+       long *ptr = buf;
+
+       while ((void *) ptr - buf < len) {
+               *ptr = seed;
+               ptr++;
+               seed *= GOLDEN_RATIO_PRIME;
+               seed >>= 3;
+       }
+}
+
+unsigned long fill_random_buf(void *buf, unsigned int len)
+{
+       unsigned long r = __rand(&__fio_rand_state);
+
+       if (sizeof(int) != sizeof(long *))
+               r *= (unsigned long) __rand(&__fio_rand_state);
+
+       __fill_random_buf(buf, len, r);
+       return r;
+}