Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 03 Oct 1996 14:00:32 -0700
From:      Josh MacDonald <jmacd@CS.Berkeley.EDU>
To:        Bruce Evans <bde@zeta.org.au>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: rand() and random() 
Message-ID:  <199610032100.OAA07079@paris.CS.Berkeley.EDU>
In-Reply-To: Your message of "Fri, 04 Oct 1996 01:38:16 %2B1000." <199610031538.BAA19908@godzilla.zeta.org.au> 

next in thread | previous 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)?

The reason I originally sent this mail is that I had been showing the
Gimp authors something with their new version dated yesterday, I clicked
on the "about dialog", which has a randomly disolved-in image.  Well, the
image materializes not randomly, but like vertical blinds gradually closing,
because the rand() function is so terrible.  Also a few of their plug-ins
use rand() (because rand() is available everywhere, while random() isn't),
and display extremeley terrible effects, (for example, layer-dissolve, 
which is supposed to be completely random, makes a bunch of stripes through
an image).

Having a bad rand() function is killing the "portability" of these 
applications.  This gave them fuel in their ongoing battle to convince
me to start running Linux.  


-josh



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