Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84 SMI; site sun.uucp Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!mtuxo!mtunh!mtung!mtunf!ariel!vax135!petsd!pesnta!amd!amdcad!decwrl!sun!guy From: guy@sun.uucp (Guy Harris) Newsgroups: net.unix Subject: Re: Precision of rand() Message-ID: <2470@sun.uucp> Date: Tue, 23-Jul-85 06:19:47 EDT Article-I.D.: sun.2470 Posted: Tue Jul 23 06:19:47 1985 Date-Received: Thu, 25-Jul-85 08:04:27 EDT References: <1244@hound.UUCP> <11392@brl-tgr.ARPA> <2399@sun.uucp> <156@ukecc.UUCP> <157@ukecc.UUCP> <211@twitch.UUCP> Organization: Sun Microsystems, Inc. Lines: 14 > > It seems that I spoke too soon. Ints on our 3B20S are indeed 4 bytes > > long. rand() returns a 4 byte value BUT (this is the catch) the value is > > masked to its lower 15 bits yeilding 0 <= rand() <= 32767. > > The length of the calculation has been 32 bits for a long time, even on > the PDP-11. The static variable, randx, is a long. See the source > routine, which is /usr/src/lib/libc/port/gen/rand.c on our machine. Yes, but the same source code reveals that the result of the calculation is ANDed with 0x7fff before being returned. All results that "rand" returns, except on UNIX/32V and its descendants (i.e., 4.xBSD), and maybe on V7 ports with 32-bit "int"s (are there any out there?), will fit in 16 bits. Guy Harris