# Multiple Random Numbers

• 02-26-2009, 09:43 PM
Multiple Random Numbers
I know how to make a method that creates a single random number, but I'm not sure how to make one that prints out multiple random numbers based on the parameter (int howMany). Here's my code for one random number:

Code:

```    public void printOneRandom()     {         int index = randomGenerator.nextInt();         System.out.println(index);     }```
• 02-26-2009, 09:47 PM
emceenugget
Use a loop.
• 02-26-2009, 10:39 PM
Do you think you could expand on that. I figured you had to use a loop but just knowing I have to use a loop doesn't help all that much.
• 02-26-2009, 10:59 PM
Fubarable
Which loop works best when you know in advance how many times you want to loop (and here you do, since that number will be passed as a parameter to the method)?

Use that loop, and try to solve this. Come on, let's see an attempt by you first. This way we'll know exactly what problems you are having.
• 02-26-2009, 11:03 PM
CJSLMAN
Loopy di loop
Some pseudo code:
Code:

```public void printManyRandomNums(int num)     {         start loop (using variable num)         int index = randomGenerator.nextInt();         System.out.println(index);         end loop     }```
The while and do-while Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)
The for Statement (The Java™ Tutorials > Learning the Java Language > Language Basics)

Luck,
CJSL
• 02-26-2009, 11:08 PM