I'd want to see if is possible to optimize performance even further of the following generate color method.package generacolorrgb;import java.util.Random;public class GeneracolorRGB {    /**     * @param args the command line arguments     */    public static void main(String[] args) {        Random r = new Random();        for (int i = 0; i < 100; i++) {            System.out.println(generateColor(r));        }    }    private static String generateColor(Random r) {        StringBuilder color = new StringBuilder(Integer.toHexString(r                .nextInt(16777215)));        while (color.length() < 6) {            color.append(0);        }        return color.append(#).reverse().toString();    }}Average time it takes on my machine: 1650704.333 ns
Generate valid random rgb color strings
java;random
Faster implementationIf you build the string yourself using a character array, you can generate the string much faster.  The slowest part of your string conversion is probably the call to Integer.toHexString().I got 2x the speed using this code:private static String generateColor(Random r) {    final char [] hex = { '0', '1', '2', '3', '4', '5', '6', '7',                          '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };    char [] s = new char[7];    int     n = r.nextInt(0x1000000);    s[0] = '#';    for (int i=1;i<7;i++) {        s[i] = hex[n & 0xf];        n >>= 4;    }    return new String(s);}I ran 10000000 iterations to test the timing vs the original code.