trinity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 08/12] Cleaned up rand32() and remove __rand32()
@ 2015-03-06 22:33 tyson.w.smith
  0 siblings, 0 replies; only message in thread
From: tyson.w.smith @ 2015-03-06 22:33 UTC (permalink / raw)
  To: davej; +Cc: trinity, Tyson Smith

From: Tyson Smith <tysmith@motorola.com>

Removed the block at the beginning of rand32() that just basically |s and ^s
rand() with rand() or a more interesting number to basically get rand again.
This is just an expensive way of getting a random number. Merged the small
switch case from __rand32() in to rand32() now that there is room.
---
 random.c | 31 ++-----------------------------
 1 file changed, 2 insertions(+), 29 deletions(-)

diff --git a/random.c b/random.c
index bf32648..ec20656 100644
--- a/random.c
+++ b/random.c
@@ -106,10 +106,9 @@ static unsigned long rept_byte(void)
 }
 
 /*
- * "selector" function for 32bit random.
- * only called from rand32()
+ * Generate, and munge a 32bit number.
  */
-static unsigned int __rand32(void)
+unsigned int rand32(void)
 {
 	unsigned long r = 0;
 
@@ -125,32 +124,6 @@ static unsigned int __rand32(void)
 	case 4:	return get_interesting_value();
 	}
 
-	return r;
-}
-
-/*
- * Generate, and munge a 32bit number.
- */
-unsigned int rand32(void)
-{
-	unsigned long r = 0;
-
-	r = __rand32();
-
-	if (rand_bool()) {
-		unsigned int i;
-		unsigned int rounds;
-
-		/* mangle it. */
-		rounds = rand() % 3;
-		for (i = 0; i < rounds; i++) {
-			if (rand_bool())
-				r |= __rand32();
-			else
-				r ^= __rand32();
-		}
-	}
-
 	/* Sometimes deduct it from INT_MAX */
 	if (rand_bool())
 		r = INT_MAX - r;
-- 
1.9.1

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

only message in thread, other threads:[~2015-03-06 22:33 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:33 [PATCH 08/12] Cleaned up rand32() and remove __rand32() 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).