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, tysmith@motorola.com,
	Tyson Smith <tyson.w.smith@gmail.com>
Subject: [PATCH 2/7] remove randbits()
Date: Mon, 16 Mar 2015 13:25:41 -0700	[thread overview]
Message-ID: <1426537541-54831-1-git-send-email-tyson.w.smith@gmail.com> (raw)

From: Tyson Smith <tyson.w.smith@gmail.com>

randbits() acts very much like rand() & rand() and does not
provide much value in this context. This function would likely
be more useful in a random bit mask scenario.
---
 random.c | 35 ++++++++---------------------------
 1 file changed, 8 insertions(+), 27 deletions(-)

diff --git a/random.c b/random.c
index 6b824bf..7917f78 100644
--- a/random.c
+++ b/random.c
@@ -68,21 +68,6 @@ unsigned long rand_single_bit(unsigned char size)
 }
 
 /*
- * set N bits, where N= rand(0 - WORDSIZE/2)
- */
-static unsigned long randbits(int limit)
-{
-	unsigned int num = rand() % (limit / 2);
-	unsigned int i;
-	unsigned long r = 0;
-
-	for (i = 0; i < num; i++)
-		r |= (1UL << (rand() % (limit - 1)));
-
-	return r;
-}
-
-/*
  * Pick 1 random byte, and repeat it through a long.
  */
 static unsigned long rept_byte(void)
@@ -104,16 +89,14 @@ unsigned int rand32(void)
 {
 	unsigned long r = 0;
 
-	switch (rand() % 5) {
+	switch (rand() % 4) {
 	case 0: r = rand_single_bit(32);
 		break;
-	case 1:	r = randbits(32);
+	case 1: r = RAND_32();
 		break;
-	case 2: r = RAND_32();
+	case 2:	r = rept_byte();
 		break;
-	case 3:	r = rept_byte();
-		break;
-	case 4:	return get_interesting_value();
+	case 3:	return get_interesting_value();
 	}
 
 	/* Sometimes deduct it from INT_MAX */
@@ -160,17 +143,15 @@ u64 rand64(void)
 
 	} else {
 		/* 33:64-bit ranges. */
-		switch (rand() % 5) {
+		switch (rand() % 4) {
 		case 0:	r = rand_single_bit(64);
 			break;
-		case 1:	r = randbits(64);
-			break;
-		case 2:	r = RAND_64();
+		case 1:	r = RAND_64();
 			break;
-		case 3:	r = rept_byte();
+		case 2:	r = rept_byte();
 			break;
 		/* Sometimes pick a not-so-random number. */
-		case 4:	return get_interesting_value();
+		case 3:	return get_interesting_value();
 		}
 
 		/* limit the size */
-- 
1.9.1

             reply	other threads:[~2015-03-16 20:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-16 20:25 tyson.w.smith [this message]
2015-03-17 14:30 ` [PATCH 2/7] remove randbits() Dave Jones

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=1426537541-54831-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).