Skip to contentSkip to conversation

simplify most significant byte modification statement

PATCH In review [email protected] 1 participant 1 message Mar 16, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 3/7 simplify most significant byte modification statement

From: Tyson Smith <[email protected]>

---
 random.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
random.c +3 -9
index 7917f78..8b4f715 100644
@@ -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))
Signature · 1 line
1.9.1