Skip to contentSkip to conversation

remove randbits()

PATCH In review [email protected] 2 participants 2 messages Mar 16, 2015 – Mar 17, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 2/7 remove randbits()

From: Tyson Smith <[email protected]>

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(-)
random.c +8 -27
index 6b824bf..7917f78 100644
@@ -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 */
Signature · 1 line
1.9.1
#1 lore raw
Quoted 5 lines · On Mon, Mar 16, 2015 at 01:25:41PM -0700, [email protected] wrote:

From: Tyson Smith <[email protected]>

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