From 1c8fd14499b87509684cb851ad5cb1e2a2aff439 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Sat, 3 Jul 2010 02:55:27 +0200 Subject: [PATCH] fast_irandom(): Implement --- random.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/random.h b/random.h index 5d15071..ea08d28 100644 --- a/random.h +++ b/random.h @@ -5,9 +5,22 @@ void fast_srandom(unsigned long seed); unsigned long fast_getseed(void); + /* Note that only 16bit numbers can be returned. */ uint16_t fast_random(unsigned int max); +/* Use this one if you want larger numbers. */ +static uint32_t fast_irandom(unsigned int max); + /* Get random number in [0..1] range. */ float fast_frandom(); + +static inline uint32_t +fast_irandom(unsigned int max) +{ + if (max <= 65536) + return fast_random(max); + return (fast_random(max / 65536 + 1) << 16) | fast_random(65536); +} + #endif -- 2.11.4.GIT