🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.transputer
Article #826

Re: Random numbers

#826
From: Rick Schubert
Date: Tue, 31 Jul 1990 19:30
34 lines
2384 bytes
In <1990Jul24.133823.6608@cunixf.cc.columbia.edu> shenkin@cunixf.cc.columbia.edu (Peter S. Shenkin) writes:

>In article <483@keele.keele.ac.uk> writes:

>>My problem is that C has the two routines srand and rand. The latter
>>returning an integer in the range 0-32767 (0 -> (2^15)-1). If I am

>C has no such thing.  UNIX has such things.  Rand and srand are outdated
>relics of the PDP-11 era, and have been replaced on almost all (?) UNIX
>systems by random and srandom, which return 32-bit values.  If your UNIX
>system supports these, use them and avoid the problem!

I don't know if all the C people have stopped reading this newsgroup, or
if they are asleep, or just don't care, but I've waited about a week and
haven't seen anyone refute this.  What you say about rand() and srand() is
just not true.  They certainly are a part of C.  That is they are a part of
ANSI C and are a part of many (most? all?) pre-ANSI C libraries.  And they
haven't been replaced on any UNIX systems that I know of; in fact, the 3
UNIX systems that I just checked (5.2, 5.3, and 5.4) all have rand()/srand()
but none of them have random() (perhaps random() is BSD).

>In any case, even on 32-bit UNIX machines when called from C, rand returns
>random values only in the 16 high-order bits, so when using these functions
>even from C it is necessary to do a 16-bit shift to the "right".  Without
>this, the sequence of numbers returned alternates strictly between even
>and odd (at least it did on a VAX running ULTRIX) -- scarcely pseudorandom
>behavior!

It's true that most versions of rand() return values in the range 0-32767,
even on 32-bit machines, but they are in the low-order bits.  If VAX/ULTRIX
returns them in the high-order bits, then either it's broken or you've
messed something up (or are confused about left/right vs. high/low).

-- Rick Schubert (rns@se-sd.sandiego.NCR.COM)
Technical Details
Message-ID: <3618@se-sd.SanDiego.NCR.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!samsung!emory!hubcap!ncrcae!ncr-sd!se-sd!rns
References: <483@keele.keele.ac.uk> <1990Jul24.133823.6608@cunixf.cc.columbia.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!samsung!emory!hubcap!ncrcae!ncr-sd!se-sd!rns
From: rns@se-sd.SanDiego.NCR.COM (Rick Schubert)
Newsgroups: comp.sys.transputer,comp.lang.fortran
Subject: Re: Random numbers
Message-ID: <3618@se-sd.SanDiego.NCR.COM>
Date: 31 Jul 90 19:30:41 GMT
References: <483@keele.keele.ac.uk> <1990Jul24.133823.6608@cunixf.cc.columbia.edu>
Organization: NCR Corporation, Systems Engineering - San Diego
Lines: 34