Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 4 Oct 1996 01:38:16 +1000
From:      Bruce Evans <bde@zeta.org.au>
To:        freebsd-hackers@FreeBSD.org, j@uriah.heep.sax.de
Cc:        jmacd@CS.Berkeley.EDU
Subject:   Re: rand() and random()
Message-ID:  <199610031538.BAA19908@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
>> Because it is ANSI conrfmant (man rand).
>
>That doesn't mean it would be impossible to do
>
>int
>rand(void)
>{
>	return (int)random();
>}

It would have to use a copy of random() so that the functions don't
mess up each other's state.

>The wrapping is needed since one function is declared to return int,
>while the other returns long.  Other than this, both have the same
>range for the result (RAND_MAX actually is (2**32)-1), so i fail to
>see why random() should _not_ match the ANSI requirements.

The example implementation of rand() in ANSI is said to be bad.  The
BSD implementation is much worse because it only throws away one high
bit instead of 17.  We had a discussion a year or two ago about
random() being bad too because srandom() uses essentially rand() to
initialize things.

>I vote for killing the old rand().  Too many things (in particular,
>games) behave very stupid with it.

Are they better with rand() replaced by (rand() % 0x7fff)?

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199610031538.BAA19908>