trinity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 07/12] Cleaned up rept8() and renamed to rept_byte()
@ 2015-03-06 22:32 tyson.w.smith
  0 siblings, 0 replies; only message in thread
From: tyson.w.smith @ 2015-03-06 22:32 UTC (permalink / raw)
  To: davej; +Cc: trinity, Tyson Smith

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

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-03-06 22:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-06 22:32 [PATCH 07/12] Cleaned up rept8() and renamed to rept_byte() tyson.w.smith

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