Re: Can not build wget-1.8 under SunOS-4.1.4
On 2001-12-16 19:02 +0100, Hrvoje Niksic wrote: Andre Majorel [EMAIL PROTECTED] writes: On 2001-12-15 07:37 +0100, Hrvoje Niksic wrote: Is there a good fallback value of RAND_MAX for systems that don't bother to define it? The standard (SUS2) says : The value of the {RAND_MAX} macro will be at least 32767. c9x says the same, but there is a subtle difference between statement and the information I actually need. A SUS-conformant system will not present a problem because it will define RAND_MAX anyway. The information I need is what RAND_MAX should fall back to on the traditional Unix systems that have rand(), but don't bother to define RAND_MAX. Online SunOS manuals are not very helpful -- the one at http://www.freebsd.org/cgi/man.cgi?query=randsektion=3manpath=SunOS+4.1.3 can't even seem to decide whether RAND_MAX is 2^31-1 or 2^15-1, and there is no mention of RAND_MAX or of an include file that might define it. 5th edition, 6th edition, 7th edition and System III all returned 0-32767. As RAND_MAX didn't exist at the time, plenty of code must have been written that assumed 0-32767. For that reason I think it unlikely that anybody ever wrote an implementation of rand() that returned less than 0-32767. I believe that a default value of 32767 is safe. Not optimal, but safe. Apparently, not all 32-bit systems use 2**31 - 1 : according to one clcm-er, MSVC defines RAND_MAX as 32767. -- André Majorel Work: [EMAIL PROTECTED] Home: [EMAIL PROTECTED] http://www.teaser.fr/~amajorel/
Re: Can not build wget-1.8 under SunOS-4.1.4
Andre Majorel [EMAIL PROTECTED] writes: 5th edition, 6th edition, 7th edition and System III all returned 0-32767. As RAND_MAX didn't exist at the time, plenty of code must have been written that assumed 0-32767. For that reason I think it unlikely that anybody ever wrote an implementation of rand() that returned less than 0-32767. But what if a rand() returns more than 0-32767? Wget's use of rand() would give incorrect results in that case because Wget uses: int waitsecs = (double)waitmax * rand () / (RAND_MAX + 1.0); But this could perhaps be remedied by explicitly limiting the result of rand() to [0, RAND_MAX). Something like: #ifndef RAND_MAX # define RAND_MAX 32767 #endif int waitsecs = (double)waitmax * (rand () % (RAND_MAX + 1)) / (RAND_MAX + 1.0); Or, even better, this could be done by a separate function with smarter logic. For example: static int random_number (int max) { int rnd = rand (); #ifndef RAND_MAX # define RAND_MAX 32767 rnd = RAND_MAX; #endif return (double)max * rnd / (RAND_MAX + 1.0); } This could also be extended to handle cases where MAX RAND_MAX, in which case it should combine the high bits from two calls to rand().
Re: Can not build wget-1.8 under SunOS-4.1.4
On 2001-12-15 07:37 +0100, Hrvoje Niksic wrote: Is there a good fallback value of RAND_MAX for systems that don't bother to define it? The standard (SUS2) says : The value of the {RAND_MAX} macro will be at least 32767. -- André Majorel Work: [EMAIL PROTECTED] Home: [EMAIL PROTECTED] http://www.teaser.fr/~amajorel/
Re: Can not build wget-1.8 under SunOS-4.1.4
Vin Shelton [EMAIL PROTECTED] writes: I have successfully built wget-1.8 under linux-2.4.xx (at home) and under SunOS-5.5, but under SunOS-4.1.4, I get a compile-time error: ../../../../src/wget-1.8/src/retr.c:682: `RAND_MAX' undeclared (first use in this fun ction) [...] Please let me know if there is more information you need. Thanks for the report. What I need is the value of RAND_MAX on SunOS, or the name of the include file it's defined in. Is there a good fallback value of RAND_MAX for systems that don't bother to define it?