projects
/
pintos-anon
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use standard POSIX "ustar" format for the scratch disk.
[pintos-anon]
/
src
/
lib
/
random.c
diff --git
a/src/lib/random.c
b/src/lib/random.c
index 63d798d6bf6394dcb017f096c5980cf4722c4fb9..a4761b6b52c14d3202a783d1e7eb1ab64baba767 100644
(file)
--- a/
src/lib/random.c
+++ b/
src/lib/random.c
@@
-29,8
+29,7
@@
swap_byte (uint8_t *a, uint8_t *b)
*b = t;
}
*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)
{
void
random_init (unsigned seed)
{
@@
-38,9
+37,6
@@
random_init (unsigned seed)
int i;
uint8_t j;
int i;
uint8_t j;
- if (inited)
- return;
-
for (i = 0; i < 256; i++)
s[i] = i;
for (i = j = 0; i < 256; i++)
for (i = 0; i < 256; i++)
s[i] = i;
for (i = j = 0; i < 256; i++)
@@
-59,7
+55,9
@@
random_bytes (void *buf_, size_t size)
{
uint8_t *buf;
{
uint8_t *buf;
- ASSERT (inited);
+ if (!inited)
+ random_init (0);
+
for (buf = buf_; size-- > 0; buf++)
{
uint8_t s_k;
for (buf = buf_; size-- > 0; buf++)
{
uint8_t s_k;
@@
-73,7
+71,9
@@
random_bytes (void *buf_, size_t size)
}
}
}
}
-/* 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)
{
unsigned long
random_ulong (void)
{