[PATCH 3/7] simplify most significant byte modification statement

[email protected] Mon, 16 Mar 2015 13:26:02 -0700
Newsgroups org.kernel.vger.trinity
Message-ID <[email protected]>
From: Tyson Smith <[email protected]>

---
 random.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/random.c b/random.c
index 7917f78..8b4f715 100644
--- a/random.c
+++ b/random.c
@@ -171,15 +171,9 @@ u64 rand64(void)
 	if (ONE_IN(25))
 		r = ~r;
 
-	/* increase distribution in MSB */
-	if (ONE_IN(10)) {
-		unsigned int i;
-		unsigned int rounds;
-
-		rounds = rand() % 4;
-		for (i = 0; i < rounds; i++)
-			r |= (1UL << ((__WORDSIZE - 1) - (rand() % 8)));
-	}
+	/* Set ~2 bits in MSB to increase distribution */
+	if (ONE_IN(10))
+		r |= (rand() & rand() & 0xffULL) << 56;
 
 	/* Sometimes flip sign */
 	if (ONE_IN(25))
-- 
1.9.1