From ab198f0a47889b5774426b5d2becb3b426032652 Mon Sep 17 00:00:00 2001 From: Pavel Charvat Date: Wed, 7 Mar 2007 13:08:18 +0100 Subject: [PATCH] Added 32bit random number generator. --- lib/lib.h | 1 + lib/random.c | 6 ++++++ 2 files changed, 7 insertions(+) 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) { -- 2.39.2