Skip to contentSkip to conversation

Decrease the likelihood of performing mangling operations

PATCH New [email protected] 1 participant 1 message Mar 6, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 10/12 Decrease the likelihood of performing mangling operations

From: Tyson Smith <[email protected]>

These operations provide value however if they happen too often it prevents the use of unmodified values that are generated that are more significant.

---
 random.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
random.c +5 -5
index d671035..fd5f2c0 100644
@@ -125,11 +125,11 @@ unsigned int rand32(void)
 	}
 
 	/* Sometimes deduct it from INT_MAX */
-	if (rand_bool())
+	if (ONE_IN(25))
 		r = INT_MAX - r;
 
 	/* Sometimes flip sign */
-	if (rand_bool())
+	if (ONE_IN(25))
 		r = ~r + 1;
 
 	/* we might get lucky if something is counting ints/longs etc. */
@@ -193,11 +193,11 @@ u64 rand64(void)
 	}
 
 	/* Sometimes invert the generated number. */
-	if (rand_bool())
+	if (ONE_IN(25))
 		r = ~r;
 
 	/* increase distribution in MSB */
-	if ((rand() % 10)) {
+	if (ONE_IN(10)) {
 		unsigned int i;
 		unsigned int rounds;
 
@@ -207,7 +207,7 @@ u64 rand64(void)
 	}
 
 	/* Sometimes flip sign */
-	if (rand_bool())
+	if (ONE_IN(25))
 		r = ~r + 1;
 
 	return r;
Signature · 1 line
1.9.1