Article View: comp.sys.amiga.tech
Article #7235Re: rand() within a range.
From: Henrik Clausen
Date: Wed, 05 Dec 1990 16:31
Date: Wed, 05 Dec 1990 16:31
27 lines
1233 bytes
1233 bytes
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___/
Technical Details
Message-ID:
<1850efff.ARN114a@adspdk.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!bagate!cbmvax!cbmehq!cbmdeo!adspdk!hclausenReferences:
<666@sheoak.bcae.oz>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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