Article View: borland.public.jbuilder.java.language
Article #16777Re: Random numbers
From: Tom Heagy
Date: Tue, 19 Jan 1999 00:00
Date: Tue, 19 Jan 1999 00:00
25 lines
1408 bytes
1408 bytes
You might also try the following code excerpt. It should return an int value
falling within a certain range. (I haven't tested it)
public static int randomNumber(int iLowNbr, int iHighNbr)
{
double dRange = iHighNbr - iLowNbr;
double dRandomNbr = Math.abs(Math.random());
int iRandomNbr = (int)Math.round((dRange * dRandomNbr)) + iLowNbr;
return iRandomNbr;
}
-Tom
Tor Iver Wilhelmsen wrote:
> Roberto Dias Torres Junior <97110751@music.pucrs.br> writes:
>
> > I'm programming a memory game and i need generate random numbers for the
> > index of cards. But i didn't find the function random in Java.
>
> Math.random(), or java.util.Random for a semirandom generator.
>
> But don't: Use ObjectSpace's JGL instead, which among other things has
> mechanisms for "shuffling" a collection.
Technical Details
Message-ID:
<36A49499.63D0200C@sciatl.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<36A47A71.49BA4453@music.pucrs.br> <ur9sr4ezq.fsf@sds.no>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,73ea12b2e0027238 X-Google-Attributes: gidf74b3,public From: Tom Heagy <tom.heagy@sciatl.com> Subject: Re: Random numbers Date: 1999/01/19 Message-ID: <36A49499.63D0200C@sciatl.com> X-Deja-AN: 434411866 Content-Transfer-Encoding: 7bit References: <36A47A71.49BA4453@music.pucrs.br> <ur9sr4ezq.fsf@sds.no> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language