random: Fix behavior of kernel option "-rs".
[pintos-anon] / src / lib / random.c
index c22414e9b779cd79123fe4390d3d0945b2d02d6c..6a963e21b42ccce71551e66e8dad806edd542d9a 100644 (file)
@@ -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)
 {
@@ -40,7 +39,7 @@ random_init (unsigned seed)
 
   if (inited)
     return;
-  
+
   for (i = 0; i < 256; i++) 
     s[i] = i;
   for (i = j = 0; i < 256; i++) 
@@ -59,7 +58,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;