*b = t;
}
-/* Initializes the PRNG with the given SEED.
- Does nothing if the PRNG has already been initialized. */
+/* Initializes or reinitializes the PRNG with the given SEED. */
void
random_init (unsigned seed)
{
int i;
uint8_t j;
- if (inited)
- return;
-
for (i = 0; i < 256; i++)
s[i] = i;
for (i = j = 0; i < 256; i++)
{
uint8_t *buf;
- ASSERT (inited);
+ if (!inited)
+ random_init (0);
+
for (buf = buf_; size-- > 0; buf++)
{
uint8_t s_k;
}
}
-/* Returns a pseudo-random unsigned long. */
+/* Returns a pseudo-random unsigned long.
+ Use random_ulong() % n to obtain a random number in the range
+ 0...n (exclusive). */
unsigned long
random_ulong (void)
{