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)];

```
use as below

```
  Random rand = new Random();

private int r = rand.nextInt(4) + 1;
private int g =  rand.nextInt(4) + 1;
private int b =  rand.nextInt(4) + 1;
private int y =  rand.nextInt(4) + 1;

    Color randomColor = new Color(r, g, b,y);

    g.setColor(randomColor);

```