Generating a random number in java?

I need to pic a random colour from an array of colours e.g.

private Color arrOfColours = {Color.red, Color.blue, Color.cyan, Color.green, Color.orange, Color.magenta};

In PHP (which I use day to day) I would just generate a random number, but Im unsure how to do this in Java of which I am less experienced.

Any help much appreciated!

thankyou very much :slight_smile:


import java.util.*;

public class PrintARandomNumberFrom0To9 {

  public static void main( String[] args ) {

    //seed the random with the current time
    Random random = new Random( new Date.getTime() ); 

    // print a 'random' number between 0 (inclusive) and 10 (exclusive) 
    System.out.println( random.nextInt( 10 ) );
  }
}