mirror of
https://github.com/moparisthebest/wget
synced 2024-07-03 16:38:41 -04:00
[svn] Use rand instead of random.
Published in <sxsu1vgataq.fsf@florida.arsdigita.de>.
This commit is contained in:
parent
9b202ba261
commit
d4c6949a05
@ -1,3 +1,7 @@
|
|||||||
|
2001-11-27 Hrvoje Niksic <hniksic@arsdigita.com>
|
||||||
|
|
||||||
|
* configure.in: Don't check for random.
|
||||||
|
|
||||||
2001-11-27 Hrvoje Niksic <hniksic@arsdigita.com>
|
2001-11-27 Hrvoje Niksic <hniksic@arsdigita.com>
|
||||||
|
|
||||||
* po/hr.po: Updated.
|
* po/hr.po: Updated.
|
||||||
|
@ -175,7 +175,7 @@ AC_FUNC_MMAP
|
|||||||
AC_CHECK_FUNCS(strdup strstr strcasecmp strncasecmp strpbrk)
|
AC_CHECK_FUNCS(strdup strstr strcasecmp strncasecmp strpbrk)
|
||||||
AC_CHECK_FUNCS(gettimeofday mktime strptime)
|
AC_CHECK_FUNCS(gettimeofday mktime strptime)
|
||||||
AC_CHECK_FUNCS(strerror snprintf vsnprintf select signal symlink access isatty)
|
AC_CHECK_FUNCS(strerror snprintf vsnprintf select signal symlink access isatty)
|
||||||
AC_CHECK_FUNCS(uname gethostname random usleep)
|
AC_CHECK_FUNCS(uname gethostname usleep)
|
||||||
|
|
||||||
dnl
|
dnl
|
||||||
dnl Check if we need to compile in getopt.c.
|
dnl Check if we need to compile in getopt.c.
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
|
2001-11-27 Hrvoje Niksic <hniksic@arsdigita.com>
|
||||||
|
|
||||||
|
* cmpt.c (random): Removed.
|
||||||
|
|
||||||
|
* retr.c (sleep_between_retrievals): Use the more portable rand()
|
||||||
|
instead of random().
|
||||||
|
|
||||||
2001-11-27 Ian Abbott <abbotti@mev.co.uk>
|
2001-11-27 Ian Abbott <abbotti@mev.co.uk>
|
||||||
|
|
||||||
* retr.c (retrieve_from_file): Initialize `new_file' to NULL to
|
* retr.c (retrieve_from_file): Initialize `new_file' to NULL to
|
||||||
|
35
src/cmpt.c
35
src/cmpt.c
@ -1222,38 +1222,3 @@ usleep (unsigned long usec)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif /* not HAVE_USLEEP */
|
#endif /* not HAVE_USLEEP */
|
||||||
|
|
||||||
|
|
||||||
#ifndef HAVE_RANDOM
|
|
||||||
/* For the systems without random: a really simple congruential RNG,
|
|
||||||
only good enough for what Wget uses it for. Before you panic: this
|
|
||||||
is not used for any kind of cryptography. */
|
|
||||||
|
|
||||||
static long random_seed;
|
|
||||||
|
|
||||||
#define RANDOM_A 9301
|
|
||||||
#define RANDOM_C 49297
|
|
||||||
#define RANDOM_M 233280
|
|
||||||
|
|
||||||
static int
|
|
||||||
random_1 (void)
|
|
||||||
{
|
|
||||||
if (!random_seed)
|
|
||||||
random_seed = time (NULL);
|
|
||||||
random_seed = (random_seed * RANDOM_A + RANDOM_C) % RANDOM_M;
|
|
||||||
return random_seed;
|
|
||||||
}
|
|
||||||
|
|
||||||
long
|
|
||||||
random (void)
|
|
||||||
{
|
|
||||||
/* Upper bits of random() are a bit more random. Compose random()
|
|
||||||
from higher bits of three call to random(). */
|
|
||||||
unsigned r1 = random_1 () >> 8;
|
|
||||||
unsigned r2 = random_1 () >> 4;
|
|
||||||
unsigned r3 = random_1 ();
|
|
||||||
long result = r1 ^ r2 ^ r3;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
#endif /* not HAVE_RANDOM */
|
|
||||||
|
@ -168,9 +168,6 @@ char *alloca ();
|
|||||||
/* Define if you have the usleep function. */
|
/* Define if you have the usleep function. */
|
||||||
#undef HAVE_USLEEP
|
#undef HAVE_USLEEP
|
||||||
|
|
||||||
/* Define if you have the random function. */
|
|
||||||
#undef HAVE_RANDOM
|
|
||||||
|
|
||||||
/* Define if you have the <string.h> header file. */
|
/* Define if you have the <string.h> header file. */
|
||||||
#undef HAVE_STRING_H
|
#undef HAVE_STRING_H
|
||||||
|
|
||||||
|
16
src/retr.c
16
src/retr.c
@ -627,6 +627,10 @@ sleep_between_retrievals (int count)
|
|||||||
{
|
{
|
||||||
static int first_retrieval = 1;
|
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 (!first_retrieval && (opt.wait || opt.waitretry))
|
||||||
{
|
{
|
||||||
if (opt.waitretry && count > 1)
|
if (opt.waitretry && count > 1)
|
||||||
@ -646,10 +650,16 @@ sleep_between_retrievals (int count)
|
|||||||
sleep (opt.wait);
|
sleep (opt.wait);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int waitsecs = random() % (opt.wait * 2 + 1);
|
int waitmax = 2 * opt.wait;
|
||||||
DEBUGP(("sleep_between_retrievals: norm=%ld,random=%ld,sleep=%d\n",
|
/* This is equivalent to rand() % waitmax, but uses the
|
||||||
|
high-order bits for better randomness. */
|
||||||
|
int waitsecs = (double)waitmax * rand () / (RAND_MAX + 1.0);
|
||||||
|
|
||||||
|
DEBUGP (("sleep_between_retrievals: norm=%ld,fuzz=%ld,sleep=%d\n",
|
||||||
opt.wait, waitsecs - opt.wait, waitsecs));
|
opt.wait, waitsecs - opt.wait, waitsecs));
|
||||||
sleep(waitsecs);
|
|
||||||
|
if (waitsecs)
|
||||||
|
sleep (waitsecs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -166,9 +166,6 @@ int vsnprintf ();
|
|||||||
#ifndef HAVE_USLEEP
|
#ifndef HAVE_USLEEP
|
||||||
int usleep ();
|
int usleep ();
|
||||||
#endif
|
#endif
|
||||||
#ifndef HAVE_RANDOM
|
|
||||||
long random ();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* SunOS brain damage -- for some reason, SunOS header files fail to
|
/* SunOS brain damage -- for some reason, SunOS header files fail to
|
||||||
declare the functions below, which causes all kinds of problems
|
declare the functions below, which causes all kinds of problems
|
||||||
|
Loading…
Reference in New Issue
Block a user