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 07/12] Cleaned up rept8() and renamed to rept_byte()
Date: Fri,  6 Mar 2015 14:32:21 -0800	[thread overview]
Message-ID: <1425681141-28612-1-git-send-email-tyson.w.smith@gmail.com> (raw)

From: Tyson Smith <tysmith@motorola.com>

This function basically generates 256 different values. These values do not
seem to have much significance and unless it has triggered results in the
past it should likely be removed.
---
 random.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/random.c b/random.c
index aab85b0..bf32648 100644
--- a/random.c
+++ b/random.c
@@ -93,16 +93,15 @@ static unsigned long randbits(int limit)
 /*
  * Pick 1 random byte, and repeat it through a long.
  */
-static unsigned long rept8(unsigned int num)
+static unsigned long rept_byte(void)
 {
-	unsigned long r = 0UL;
-	unsigned int i;
-	unsigned char c;
-
-	c = RAND_BYTE();
-	for (i = rand() % (num - 1) ; i > 0; --i)
-		r = (r << 8) | c;
+	unsigned long r = RAND_BYTE();
 
+	r = (r << 8) | r;
+	r = (r << 16) | r;
+#if __WORDSIZE == 64
+	r = (r << 32) | r;
+#endif
 	return r;
 }
 
@@ -121,7 +120,7 @@ static unsigned int __rand32(void)
 		break;
 	case 2: r = RAND_32();
 		break;
-	case 3:	r = rept8(4);
+	case 3:	r = rept_byte();
 		break;
 	case 4:	return get_interesting_value();
 	}
@@ -203,7 +202,7 @@ u64 rand64(void)
 			break;
 		case 2:	r = RAND_64();
 			break;
-		case 3:	r = rept8(8);
+		case 3:	r = rept_byte();
 			break;
 		/* Sometimes pick a not-so-random number. */
 		case 4:	return get_interesting_value();
-- 
1.9.1

                 reply	other threads:[~2015-03-06 22:32 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=1425681141-28612-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 read-only IMAP folder(s) and NNTP newsgroup(s).