X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/ec68c7d9fca00e976df02842dc2c9d5a523567af..4e5acdb9a2894eca56cb7ffa022635b9af35acef:/sbr/m_rand.c diff --git a/sbr/m_rand.c b/sbr/m_rand.c index a05bb4ab..bac97507 100644 --- a/sbr/m_rand.c +++ b/sbr/m_rand.c @@ -6,26 +6,30 @@ */ #include /* for abs(), srand(), rand(), arc4random() */ +#include #include /* for fopen(), fread(), fclose() */ #include /* for getpid() */ #include /* for time() */ #include +#include "m_rand.h" #if !HAVE_ARC4RANDOM -static int seeded = 0; +static bool seeded = false; #endif int -m_rand (unsigned char *buf, size_t n) { +m_rand (unsigned char *buf, size_t n) +{ #if !HAVE_ARC4RANDOM if (! seeded) { FILE *devurandom; unsigned int seed; if ((devurandom = fopen ("/dev/urandom", "r"))) { - if (fread (&seed, sizeof (seed), 1, devurandom) == 1) seeded = 1; + if (fread (&seed, sizeof (seed), 1, devurandom) == 1) + seeded = true; fclose (devurandom); } @@ -35,7 +39,7 @@ m_rand (unsigned char *buf, size_t n) { arXiv:1005.4117v1 [physics.comp-ph], 22 May 2010, p. 19. time() and getpid() shouldn't fail on POSIX platforms. */ seed = abs ((int) ((time (0) * 181 * ((getpid ()-83) * 359)) % 104729)); - seeded = 1; + seeded = true; } srand (seed);