Question: i want to choose randomly colors, but only between of them (Red, Blue, Green and Yellow), here some of the code i'm trying.

```
public class LittleBall extends JPanel {

private Random random = new Random();
private float r = random.nextFloat();
private float g = random.nextFloat();
private float b = random.nextFloat();

.....

public void paint (Graphics g) {

Color randomColor = new Color(r, this.g, b);

g.setColor(randomColor);

    }

}

```

But this just give every color in the world o.O, of course because the nextFloat of the r,g, and b variables is giving random numbers. But i just want to give go between colors.

Thanks.

Answer: 
**Create an array of Colors and get a Color randomly.**

```
Color[] colors = new Color[] { Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW };

Color randomColor = colors[(int)( Math.random() * 4)];

// or try this one
//Color randomColor = colors[new Random().nextInt(4)];

```
`Math.random()` returns a random number between 0 and 1. By multiplying this value by a range of numbers, you can choose any value between the min and max. Then you will likely need to cast it to an int in order to get an actual value for R, G, and/or B.

```
int r = (int) Math.random() * ( max - min )

```

will give you an `r` value between the specified `min` and `max`. Therefore, you can select the range as follows:

```
int r = (int) Math.random() * ( 255 - 100 )

```

will give you a value for Red between 100 and 255. You can, of course, just do the subtraction in your head and just put 

```
int r = (int) Math.random() * ( 155 )

```

You can repeat this value for Green and Blue as well.

You can probably also use float values if you like. The int will simply truncate the decimal values from your result. 

EDIT: Seeing what you have so far, you should definitely use float, not int.