Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 4 Oct 1996 20:22:33 +0200 (MET DST)
From:      J Wunsch <j@uriah.heep.sax.de>
To:        freebsd-hackers@freebsd.org (FreeBSD hackers)
Subject:   Re: rand() and random()
Message-ID:  <199610041822.UAA03607@uriah.heep.sax.de>
In-Reply-To: <199610031538.BAA19908@godzilla.zeta.org.au> from Bruce Evans at "Oct 4, 96 01:38:16 am"

next in thread | previous in thread | raw e-mail | index | archive | help
As Bruce Evans wrote:

> >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.

...unless it's documented that they mess with it. :) It's unlikely
that one program uses both functions (and if so, it's as likely that
the lousy programmer would have messed rand()'s state with rand() in
another place as well ;-).

> >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)?

I don't think so.  But they are much better with random().  See xmine,
if you wanna get a nice example.  It generates totally predictable
layouts when using rand().

-- 
cheers, J"org

joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)



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