trinity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 05/12] Make rand_bool a macro
@ 2015-03-06 22:31 tyson.w.smith
  0 siblings, 0 replies; only message in thread
From: tyson.w.smith @ 2015-03-06 22:31 UTC (permalink / raw)
  To: davej; +Cc: trinity, Tyson Smith

From: Tyson Smith <tysmith@motorola.com>

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(-)

diff --git a/include/random.h b/include/random.h
index 69ccfa3..b8f8d2c 100644
--- a/include/random.h
+++ b/include/random.h
@@ -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);
diff --git a/random.c b/random.c
index 063912f..a1ff7a8 100644
--- a/random.c
+++ b/random.c
@@ -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)
  */
-- 
1.9.1

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-03-06 22:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-06 22:31 [PATCH 05/12] Make rand_bool a macro tyson.w.smith

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).