Make rand_bool a macro
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
@@ -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
@@ -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