Powerball Example (Generating Random Numbers)

I have to do an assignment where I have to write a program that simulates the selection of Powerball lottery numbers. I have to use the Math.random() function to simulate the random selection of a numbered ball. There has to be five white balls and one red ball. The five white numbers must be unique and between 1 and 49. (After a ball is removed from the container, it can’t be selected again.) The one red number must be between 1 and 42. The red number can possibly be the same number as one of the selected

white balls.

I'm so close to figuring this one out; the only issue is that when I enter a number, I get an endless loop (it compiles fine). I can't seem to figure out what's wrong with my code. Any advice? Thanks.

Code:

`import java.util.Random;`

public class PowerBall

{

public static void main(String [] args)

{

int w = Integer.parseInt(args[0]);

int r = Integer.parseInt(args[1]);

int g = Integer.parseInt(args[2]);

for (int i = 1; i <= w; i++)

{

if (w != g)

{

System.out.println(w);

}

else

{

System.out.println("You already picked this number");

}

}

for (int random = 1; random <= r; random++)

{

int rand = (int) Math.random();

random = (rand + 1);

}

System.out.println("You picked numbers " + w + " and " + r);

}

}