Skip to contentSkip to conversation

Make rand_bool a macro

PATCH New [email protected] 1 participant 1 message Mar 6, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 5/12 Make rand_bool a macro

From: Tyson Smith <[email protected]>

Since rand_bool is used a heavily used operation simplifying it may shave off some cycles here and there. Also replaced %2 with &1 with the same intention.

---
 include/random.h | 3 ++-
 random.c         | 5 -----
 2 files changed, 2 insertions(+), 6 deletions(-)
include/random.h +2 -1
index 69ccfa3..b8f8d2c 100644
@@ -13,6 +13,8 @@
 #error "Unexpected RAND_MAX value. Please add support."
 #endif
 
+#define rand_bool()				(rand() & 1)
+
 extern unsigned int seed;
 unsigned int init_seed(unsigned int seed);
 void set_seed(struct childdata *child);
@@ -20,7 +22,6 @@ void reseed(void);
 unsigned int new_seed(void);
 
 void generate_rand_bytes(unsigned char *ptr, unsigned int len);
-unsigned int rand_bool(void);
 unsigned int rand32(void);
 u64 rand64(void);
 unsigned int rand_range(unsigned int min, unsigned int max);
random.c +0 -5
index 063912f..a1ff7a8 100644
@@ -64,11 +64,6 @@ unsigned long set_rand_bitmask(unsigned int num, const unsigned long *values)
 	return mask;
 }
 
-unsigned int rand_bool(void)
-{
-	return rand() % 2;
-}
-
 /*
  * Pick a random power of two between 2^0 and 2^(__WORDSIZE-1)
  */
Signature · 1 line
1.9.1