From owner-freebsd-hackers Thu Oct 3 14:04:38 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id OAA23422 for hackers-outgoing; Thu, 3 Oct 1996 14:04:38 -0700 (PDT) Received: from paris.CS.Berkeley.EDU (paris.CS.Berkeley.EDU [128.32.34.47]) by freefall.freebsd.org (8.7.5/8.7.3) with SMTP id OAA23410 for ; Thu, 3 Oct 1996 14:04:36 -0700 (PDT) Received: from paris.CS.Berkeley.EDU (localhost.Berkeley.EDU [127.0.0.1]) by paris.CS.Berkeley.EDU (8.6.11/8.6.9) with ESMTP id OAA07079; Thu, 3 Oct 1996 14:00:34 -0700 From: Josh MacDonald Message-Id: <199610032100.OAA07079@paris.CS.Berkeley.EDU> To: Bruce Evans Cc: freebsd-hackers@freebsd.org Subject: Re: rand() and random() In-reply-to: Your message of "Fri, 04 Oct 1996 01:38:16 +1000." <199610031538.BAA19908@godzilla.zeta.org.au> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <7072.844376431.1@paris.CS.Berkeley.EDU> Date: Thu, 03 Oct 1996 14:00:32 -0700 Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk > >> 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