From: Pavel Charvat Date: Wed, 7 Mar 2007 12:08:18 +0000 (+0100) Subject: Added 32bit random number generator. X-Git-Tag: holmes-import~506^2~104 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=ab198f0a47889b5774426b5d2becb3b426032652;p=libucw.git Added 32bit random number generator. --- diff --git a/lib/lib.h b/lib/lib.h index 42f11506..c6b558d1 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -209,6 +209,7 @@ int rx_subst(regex *r, byte *by, byte *src, byte *dest, uns destlen); /* random.c */ +uns random_u32(void); uns random_max(uns max); u64 random_u64(void); u64 random_max_u64(u64 max); diff --git a/lib/random.c b/lib/random.c index 211986b7..a771c97a 100644 --- a/lib/random.c +++ b/lib/random.c @@ -14,6 +14,12 @@ /* We expect the random generator in libc to give at least 30 bits of randomness */ COMPILE_ASSERT(RAND_MAX_RANGE_TEST, RAND_MAX >= (1 << 30)-1); +uns +random_u32(void) +{ + return (random() & 0xffff) | ((random() & 0xffff) << 16); +} + uns random_max(uns max) {