From 65e976d70c3f196b8548824b02551254219f2412 Mon Sep 17 00:00:00 2001 From: "Peter D. Gray" Date: Fri, 12 Jan 2018 13:17:58 -0500 Subject: [PATCH] rand.c: platform depedenant code can be removed using CPP flag --- rand.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/rand.c b/rand.c index 2770c30ec4..9d43850f7b 100644 --- a/rand.c +++ b/rand.c @@ -30,6 +30,8 @@ #include "rand.h" +#ifndef RAND_PLATFORM_INDEPENDANT + static FILE *frand = NULL; int finalize_rand(void) @@ -62,13 +64,6 @@ uint32_t random32(void) #endif } -uint32_t random_uniform(uint32_t n) -{ - uint32_t x, max = 0xFFFFFFFF - (0xFFFFFFFF % n); - while ((x = random32()) >= max); - return x / (max / n); -} - void random_buffer(uint8_t *buf, size_t len) { #ifdef _WIN32 @@ -87,6 +82,19 @@ void random_buffer(uint8_t *buf, size_t len) #endif } +#endif /* RAND_PLATFORM_INDEPENDANT */ + +// +// Following code should be platform independant +// + +uint32_t random_uniform(uint32_t n) +{ + uint32_t x, max = 0xFFFFFFFF - (0xFFFFFFFF % n); + while ((x = random32()) >= max); + return x / (max / n); +} + void random_permute(char *str, size_t len) { int i, j;