* [PATCH 10/12] Decrease the likelihood of performing mangling operations
@ 2015-03-06 22:35 tyson.w.smith
0 siblings, 0 replies; only message in thread
From: tyson.w.smith @ 2015-03-06 22:35 UTC (permalink / raw)
To: davej; +Cc: trinity, Tyson Smith
From: Tyson Smith <tysmith@motorola.com>
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(-)
diff --git a/random.c b/random.c
index d671035..fd5f2c0 100644
--- a/random.c
+++ b/random.c
@@ -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;
--
1.9.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2015-03-06 22:35 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:35 [PATCH 10/12] Decrease the likelihood of performing mangling operations 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).