Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!bagate!cbmvax!cbmehq!cbmdeo!adspdk!hclausen From: hclausen@adspdk.UUCP (Henrik Clausen) Newsgroups: comp.sys.amiga.tech Subject: Re: rand() within a range. Message-ID: <1850efff.ARN114a@adspdk.UUCP> Date: 5 Dec 90 16:31:43 GMT References: <666@sheoak.bcae.oz> Reply-To: hclausen@adspdk.UUCP Followup-To: comp.sys.amiga.tech Organization: Graffiti Data Lines: 27 In article <666@sheoak.bcae.oz>, David Thiele writes: > Is there a way to generate random numbers within a certain range in > Lattice C??. Ive done it with the following code but it's not very > elegant (or fast!). You said it :-) Try something like: int Random(int Range) { return((int)(Range * drand48())); } Add offsets at your desire. Seed from the timer with srand48(). drand48() returns a double, and is supposed to be quite good. BTW, this stuff is in your manual. -Henrik | Henrik Clausen, Graffiti Data | If the Doors of Perception where cleansed, | | ...{pyramid|rutgers}!cbmvax! | Man would see Reality as it is - Infinite. | \______cbmehq!adspdk!hclausen___|_________________________________W. Blake___/