browse: forums | FAQ
Connecting Tech Pros Worldwide

Hey there! Do you need Java help?

Get answers from our community of Java experts on BYTES! It's free.

random number generator

Newbie
 
Join Date: Sep 2007
Posts: 1
#1: Sep 15 '07
im in a java class and need to make a program that displays 6 random numbers between 1 and 49. ive gotten the display part to work... but the random generator confounds my logic. help PLEASE



Member
 
Join Date: Sep 2007
Location: UK
Posts: 40
#2: Sep 16 '07

re: random number generator


One way to do this is by using the Random class within the java util package. The nextInt(int n) method will solve your problem (Returns an int value between 0 and the specified value(n) minus 1!). Of course you will need a loop too since you need 6 numbers.
Good luck :-)
Newbie
 
Join Date: Sep 2007
Posts: 4
#3: Sep 16 '07

re: random number generator


Quote:

Originally Posted by cwalster

im in a java class and need to make a program that displays 6 random numbers between 1 and 49. ive gotten the display part to work... but the random generator confounds my logic. help PLEASE

you can use nextInt(int) method of the java.util.Random class, found in java documentation. also u can find an example overthere.
MarkoKlacar's Avatar
Expert
 
Join Date: Aug 2007
Location: Stockholm, Sweden
Posts: 294
#4: Sep 17 '07

re: random number generator


Hi,

just a word of advice, the nextInt(Number) begins at '0', so if you want to generate a number between 1-49 don't forget to add the '+1' after nextInt(Number).

If you already didn't figure that one out.
Reply