trinity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tyson.w.smith@gmail.com
To: davej@codemonkey.org.uk
Cc: trinity@vger.kernel.org, Tyson Smith <tysmith@motorola.com>
Subject: [PATCH 08/12] Cleaned up rand32() and remove __rand32()
Date: Fri,  6 Mar 2015 14:33:48 -0800	[thread overview]
Message-ID: <1425681228-28673-1-git-send-email-tyson.w.smith@gmail.com> (raw)

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

                 reply	other threads:[~2015-03-06 22:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1425681228-28673-1-git-send-email-tyson.w.smith@gmail.com \
    --to=tyson.w.smith@gmail.com \
    --cc=davej@codemonkey.org.uk \
    --cc=trinity@vger.kernel.org \
    --cc=tysmith@motorola.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).