How can I stop the color from being chosen in a row?
I'm trying to avoid repeating the same colors in a row chosen from the array. I have tried comparing if the colors are equal but haven't been able to skip the color when chosen randomly again.
Color color[]={Color.YELLOW,Color.MAGENTA,Color.BLACK,new Color(0x964B00),new Color(0xB57EDC)};
Random rand=new Random();
Color newColor = color[rand.nextInt(5)];
for(int i=0;i<5;i++){
if(newColor.equals(color[i]));{
newColor=color[rand.nextInt(5)];
}
myPanel.colorArray[myPanel.mouseDownGridX][myPanel.mouseDownGridY] = newColor;
myPanel.repaint();
}