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=rand&sektion=3&manpath=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/

Reply via email to