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

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

--
To unsubscribe from this list: send the line "unsubscribe trinity" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to