rnd-20030313-1-src
[rocksndiamonds.git] / src / libgame / misc.c
index e5cdfe26da8efec03bb294f2c2218c7081074b01..d94b37d55c174a63a3684ca2266ac19ed349dc12 100644 (file)
@@ -261,74 +261,66 @@ void WaitUntilDelayReached(unsigned long *counter_var, unsigned long delay)
 /* random generator functions                                                */
 /* ------------------------------------------------------------------------- */
 
+#if 0
 unsigned int SimpleRND(unsigned int max)
 {
-#if defined(TARGET_SDL)
-  static unsigned long root = 654321;
-  unsigned long current_ms;
+  return (random_linux_libc(RND_FREE) % max);
+}
 
-  current_ms = SDL_GetTicks();
-  root = root * 4253261 + current_ms;
-  return (root % max);
-#else
-  static unsigned long root = 654321;
-  struct timeval current_time;
+unsigned int InitSimpleRND(long seed)
+{
+  if (seed == NEW_RANDOMIZE)
+  {
+    struct timeval current_time;
 
-  gettimeofday(&current_time, NULL);
-  root = root * 4253261 + current_time.tv_sec + current_time.tv_usec;
-  return (root % max);
-#endif
-}
+    gettimeofday(&current_time, NULL);
+    seed = (long)current_time.tv_usec;
+  }
 
-#ifdef DEBUG
-static unsigned int last_RND_value = 0;
+  srandom_linux_libc(RND_FREE, (unsigned int) seed);
 
-unsigned int last_RND()
-{
-  return last_RND_value;
+  return (unsigned int) seed;
 }
-#endif
 
 unsigned int RND(unsigned int max)
 {
-#ifdef DEBUG
-  return (last_RND_value = random_linux_libc() % max);
-#else
-  return (random_linux_libc() % max);
-#endif
+  return (random_linux_libc(RND_GAME) % max);
 }
 
 unsigned int InitRND(long seed)
 {
-#if defined(TARGET_SDL)
-  unsigned long current_ms;
-
   if (seed == NEW_RANDOMIZE)
   {
-    current_ms = SDL_GetTicks();
-    srandom_linux_libc((unsigned int) current_ms);
-    return (unsigned int) current_ms;
-  }
-  else
-  {
-    srandom_linux_libc((unsigned int) seed);
-    return (unsigned int) seed;
+    struct timeval current_time;
+
+    gettimeofday(&current_time, NULL);
+    seed = (long)current_time.tv_usec;
   }
-#else
-  struct timeval current_time;
 
+  srandom_linux_libc(RND_GAME, (unsigned int) seed);
+
+  return (unsigned int) seed;
+}
+#endif
+
+unsigned int init_random_number(int nr, long seed)
+{
   if (seed == NEW_RANDOMIZE)
   {
+    struct timeval current_time;
+
     gettimeofday(&current_time, NULL);
-    srandom_linux_libc((unsigned int) current_time.tv_usec);
-    return (unsigned int) current_time.tv_usec;
-  }
-  else
-  {
-    srandom_linux_libc((unsigned int) seed);
-    return (unsigned int) seed;
+    seed = (long)current_time.tv_usec;
   }
-#endif
+
+  srandom_linux_libc(nr, (unsigned int) seed);
+
+  return (unsigned int) seed;
+}
+
+unsigned int get_random_number(int nr, unsigned int max)
+{
+  return (random_linux_libc(nr) % max);
 }