-
[physik/morpheus.git] / random.c
index b2e11fd..c81dffa 100644 (file)
--- a/random.c
+++ b/random.c
@@ -6,6 +6,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <sys/types.h>
+#include <unistd.h>
 
 #include "defines.h"
 
@@ -13,6 +15,7 @@
 extern u32 gr;
 extern int random_fd;
 extern u32 *rand_buf,*rand_current;
+extern char random_file[MAX_CHARS_RANDOM_FILE];
 
 /* return random integer between 0 - max-1 */
 u32 rand_get(u32 max) 
@@ -22,9 +25,17 @@ u32 rand_get(u32 max)
   printfd("debug: reading new random bytes\n");
   if(read(random_fd,rand_buf,RAND_BUF_SIZE)!=RAND_BUF_SIZE)
   {
-   puts("failed reading 1 mega bytes of random data");
-   return -23;
+   if(!strcmp(random_file,""))
+   {
+    puts("random file end, starting over ...");
+    lseek(random_fd,0,SEEK_SET);
+   } else
+   {
+    puts("failed reading 1 mega bytes of random data");
+    return -23;
+   }
   }
+  printfd("debug: finished reading random bytes\n");
   rand_current=rand_buf;
  }
  /* cells numbered 0...max-1 */