]> sjero.net Git - wget/blobdiff - src/retr.c
[svn] Use the new function `random_number' that doesn't depend on RAND_MAX
[wget] / src / retr.c
index 44229cba9f492dd5dbc2a915f7850d38d9076576..6bd885894c429a0ce7f86897541ba51d1701ed42 100644 (file)
@@ -653,10 +653,6 @@ sleep_between_retrievals (int count)
 {
   static int first_retrieval = 1;
 
-  if (first_retrieval && opt.random_wait)
-    /* --random-wait uses the RNG, so seed it. */
-    srand (time (NULL));
-
   if (!first_retrieval && (opt.wait || opt.waitretry))
     {
       if (opt.waitretry && count > 1)
@@ -676,10 +672,10 @@ sleep_between_retrievals (int count)
            sleep (opt.wait);
          else
            {
-             int waitmax = 2 * opt.wait;
-             /* This is equivalent to rand() % waitmax, but uses the
-                high-order bits for better randomness.  */
-             int waitsecs = (double)waitmax * rand () / (RAND_MAX + 1.0);
+             /* Sleep a random amount of time averaging in opt.wait
+                seconds.  The sleeping amount ranges from 0 to
+                opt.wait*2, inclusive.  */
+             int waitsecs = random_number (opt.wait * 2 + 1);
 
              DEBUGP (("sleep_between_retrievals: norm=%ld,fuzz=%ld,sleep=%d\n",
                       opt.wait, waitsecs - opt.wait, waitsecs));