random numbers

A

Ams

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...
 
T

TechBookReport

Ams said:
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
 
M

Malte

Ams said:
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;

?
 
A

Alun Harford

Ams said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,044
Latest member
RonaldNen

Latest Threads

Top