From owner-freebsd-hackers Thu Oct 3 06:33:59 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id GAA26499 for hackers-outgoing; Thu, 3 Oct 1996 06:33:59 -0700 (PDT) Received: from irz301.inf.tu-dresden.de (irz301.inf.tu-dresden.de [141.76.1.11]) by freefall.freebsd.org (8.7.5/8.7.3) with SMTP id GAA26459 for ; Thu, 3 Oct 1996 06:33:54 -0700 (PDT) Received: from sax.sax.de (sax.sax.de [193.175.26.33]) by irz301.inf.tu-dresden.de (8.6.12/8.6.12-s1) with ESMTP id PAA18975; Thu, 3 Oct 1996 15:33:31 +0200 Received: (from uucp@localhost) by sax.sax.de (8.6.12/8.6.12-s1) with UUCP id PAA02947; Thu, 3 Oct 1996 15:33:31 +0200 Received: (from j@localhost) by uriah.heep.sax.de (8.7.5/8.6.9) id OAA26494; Thu, 3 Oct 1996 14:52:26 +0200 (MET DST) From: J Wunsch Message-Id: <199610031252.OAA26494@uriah.heep.sax.de> Subject: Re: rand() and random() To: freebsd-hackers@freebsd.org (FreeBSD hackers) Date: Thu, 3 Oct 1996 14:52:26 +0200 (MET DST) Cc: jmacd@CS.Berkeley.EDU Reply-To: joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch) In-Reply-To: <199610022202.PAA04883@phaeton.artisoft.com> from Terry Lambert at "Oct 2, 96 03:02:42 pm" X-Phone: +49-351-2012 669 X-PGP-Fingerprint: DC 47 E6 E4 FF A6 E9 8F 93 21 E0 7D F9 12 D6 4E X-Mailer: ELM [version 2.4ME+ PL17 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk As Terry Lambert wrote: > > I'm curious why rand() still exists. Everyone knows its really > > bad. Why not just ditch it in favor of random()? > > Because it is ANSI conrfmant (man rand). That doesn't mean it would be impossible to do int rand(void) { return (int)random(); } 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. (From random(3):) Unlike srand, srandom() does not return the old seed; the reason for ^^^^^^^^^^^^ this is that the amount of state information used is much more than a single word. (Two other routines are provided to deal with restart- The marked phrase is wrong. srand() doesn't return the old seed either, at least not in the ANSI version. ISRT that it used to return the old seed in obsolete implementations. ing/changing random number generators). Like rand(3), however, random() will by default produce a sequence of numbers that can be duplicated by calling srandom() with `1' as the seed. ...so this also matches the ANSI requirements. There is absolutely no reason for still supporting the old junk. The extended interface of srandom() doesn't hurt, since extensions are, of course, possible. I vote for killing the old rand(). Too many things (in particular, games) behave very stupid with it. -- 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. ;-)