Velocity Reviews > Java > random numbers

# random numbers

Ams
Guest
Posts: n/a

 02-23-2005
hi,
I am writing a method to invoke random numbers. I need the numbers to
be in the range 0-1000 but the numbers that i have created are huge
with around 7 digits. Does anyone no how or if its even possible to do
this??
Would greatly appreciate any help...

TechBookReport
Guest
Posts: n/a

 02-23-2005
Ams wrote:
> hi,
> I am writing a method to invoke random numbers. I need the numbers to
> be in the range 0-1000 but the numbers that i have created are huge
> with around 7 digits. Does anyone no how or if its even possible to do
> this??
> Would greatly appreciate any help...

Look at the nextInt(int n) method, this returns a random int between 0
and n-1.

HTH
================================================== ============
TechBookReport Java: http://www.techbookreport.com/JavaIndex.html

Malte
Guest
Posts: n/a

 02-23-2005
Ams wrote:
> hi,
> I am writing a method to invoke random numbers. I need the numbers to
> be in the range 0-1000 but the numbers that i have created are huge
> with around 7 digits. Does anyone no how or if its even possible to do
> this??
> Would greatly appreciate any help...

Hmm, it's been a while, but something like this:

int bigRandom;
int myRandom;

myRandom = (bigRandom%1000) + 1;

?

Alun Harford
Guest
Posts: n/a

 02-23-2005
"Ams" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
> hi,
> I am writing a method to invoke random numbers. I need the numbers to
> be in the range 0-1000 but the numbers that i have created are huge
> with around 7 digits. Does anyone no how or if its even possible to do
> this??
> Would greatly appreciate any help...

java.util.Random random = new java.util.Random();
int requiredRandomNumber = random.nextInt(1001);

Alun Harford