X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pintos-anon;a=blobdiff_plain;f=src%2Flib%2Frandom.c;h=a4761b6b52c14d3202a783d1e7eb1ab64baba767;hp=c22414e9b779cd79123fe4390d3d0945b2d02d6c;hb=53a7f5d0952a4595f252247f5ee3d017468eb57e;hpb=e5439c03526c8e2881b0430ddbfe02812bee2e68 diff --git a/src/lib/random.c b/src/lib/random.c index c22414e..a4761b6 100644 --- a/src/lib/random.c +++ b/src/lib/random.c @@ -29,8 +29,7 @@ swap_byte (uint8_t *a, uint8_t *b) *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) { @@ -38,9 +37,6 @@ 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++) @@ -59,7 +55,9 @@ random_bytes (void *buf_, size_t size) { uint8_t *buf; - ASSERT (inited); + if (!inited) + random_init (0); + for (buf = buf_; size-- > 0; buf++) { uint8_t s_k;