trinity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/7] remove randbits()
@ 2015-03-16 20:25 tyson.w.smith
  2015-03-17 14:30 ` Dave Jones
  0 siblings, 1 reply; 2+ messages in thread
From: tyson.w.smith @ 2015-03-16 20:25 UTC (permalink / raw)
  To: davej; +Cc: trinity, tysmith, Tyson Smith

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 2/7] remove randbits()
  2015-03-16 20:25 [PATCH 2/7] remove randbits() tyson.w.smith
@ 2015-03-17 14:30 ` Dave Jones
  0 siblings, 0 replies; 2+ messages in thread
From: Dave Jones @ 2015-03-17 14:30 UTC (permalink / raw)
  To: tyson.w.smith; +Cc: trinity, tysmith

On Mon, Mar 16, 2015 at 01:25:41PM -0700, tyson.w.smith@gmail.com wrote:
 > 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.

Where are we doing rand() & rand() ?
The changelog implies we're doing this elsewhere, and that this
is duplication, but I'm not seeing it.

	Dave

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-03-17 14:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-16 20:25 [PATCH 2/7] remove randbits() tyson.w.smith
2015-03-17 14:30 ` Dave Jones

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