summaryrefslogtreecommitdiff
path: root/src/rand-isaac.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2005-12-12 22:42:58 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2005-12-12 22:42:58 +0000
commitb22d6cc592e5488619a7d3d7875d360465f714d3 (patch)
tree5d38759b0c9d86e9efc2017df90f084fc44aa170 /src/rand-isaac.c
parentd2af4ddbeb6b42b55a719addfb3ba7397bf169e6 (diff)
downloadcoreutils-b22d6cc592e5488619a7d3d7875d360465f714d3.tar.xz
(struct irand_state, irand_init, irand32, irand_mod): Move to shred.c.
Diffstat (limited to 'src/rand-isaac.c')
-rw-r--r--src/rand-isaac.c60
1 files changed, 0 insertions, 60 deletions
diff --git a/src/rand-isaac.c b/src/rand-isaac.c
index 4bd99d255..3fc6b62fa 100644
--- a/src/rand-isaac.c
+++ b/src/rand-isaac.c
@@ -333,63 +333,3 @@ isaac_seed (struct isaac_state *s)
isaac_seed_finish (s);
}
-
-/* Single-word RNG built on top of ISAAC */
-struct irand_state
-{
- uint32_t r[ISAAC_WORDS];
- unsigned int numleft;
- struct isaac_state *s;
-};
-
-static void
-irand_init (struct irand_state *r, struct isaac_state *s)
-{
- r->numleft = 0;
- r->s = s;
-}
-
-/*
- * We take from the end of the block deliberately, so if we need
- * only a small number of values, we choose the final ones which are
- * marginally better mixed than the initial ones.
- */
-static uint32_t
-irand32 (struct irand_state *r)
-{
- if (!r->numleft)
- {
- isaac_refill (r->s, r->r);
- r->numleft = ISAAC_WORDS;
- }
- return r->r[--r->numleft];
-}
-
-/*
- * Return a uniformly distributed random number between 0 and n,
- * inclusive. Thus, the result is modulo n+1.
- *
- * Theory of operation: as x steps through every possible 32-bit number,
- * x % n takes each value at least 2^32 / n times (rounded down), but
- * the values less than 2^32 % n are taken one additional time. Thus,
- * x % n is not perfectly uniform. To fix this, the values of x less
- * than 2^32 % n are disallowed, and if the RNG produces one, we ask
- * for a new value.
- */
-static uint32_t
-irand_mod (struct irand_state *r, uint32_t n)
-{
- uint32_t x;
- uint32_t lim;
-
- if (!++n)
- return irand32 (r);
-
- lim = -n % n; /* == (2**32-n) % n == 2**32 % n */
- do
- {
- x = irand32 (r);
- }
- while (x < lim);
- return x % n;
-}