Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!jarthur!elroy.jpl.nasa.gov!decwrl!pa.dec.com!mogul From: mogul@wrl.dec.com (Jeffrey Mogul) Newsgroups: comp.unix.ultrix Subject: Re: rand() ... works ?? Message-ID: <1991Feb5.023158.21360@pa.dec.com> Date: 5 Feb 91 02:31:58 GMT References: Sender: news@pa.dec.com (News) Distribution: comp Organization: DEC Western Research Lines: 28 In article josevela@academ01.mty.itesm.mx (Jose Angel Vela Avila) writes: > I have been trying the rand() function, but seems don't work... > > I'm on a Vax 6310 with Ultrix 3.0, rand() returns me values too much hi.. > > Is there a trick ? The rand() function is defined as returning an integer in the range between 0 and (2^31)-1, inclusive. Since the upper end of the range is the largest possible (signed) integer, there is no possible return value that is "too high". If what you mean is that you don't WANT values larger than some value of your choosing ... the usual trick is to do myrand(x) int x; { return (rand() % x); } which returns an integer between 0 and x-1, inclusive. But you really should be using the random() function, rather than rand(). Using rand() this way will produce non-random results. See the manual page for random(3). -Jeff