Java Utililty Methods Random Color

List of utility methods to do Random Color

Description

The list of methods to do Random Color are organized into topic(s).

Method

StringgetRandomColorInString()
get Random Color In String
Random numGen = new Random();
return new String(numGen.nextInt(256) + ", " + numGen.nextInt(256) + ", " + numGen.nextInt(256));
ColorgetRandomColour()
Get a random colour from a set of a given size.
if (generator == null) {
    generator = new Random();
float h = generator.nextFloat();
if (h > 0.1f && h < 0.25f) {
    h -= 0.15f; 
return Color.getHSBColor(h, 1.0F, 0.9F);
...
StringgetRandomHexColor()
get Random Hex Color
String hex1 = getRandomHex();
String hex2 = getRandomHex();
String hex3 = getRandomHex();
String hex4 = getRandomHex();
String hex5 = getRandomHex();
String hex6 = getRandomHex();
String color = "#" + hex1 + hex2 + hex3 + hex4 + hex5 + hex6;
return color;
...
StringgetRandomHexColor()
get Random Hex Color
float hue = random.nextFloat();
float saturation = (random.nextInt(2000) + 1000) / 10000f;
float luminance = 0.9f;
Color color = Color.getHSBColor(hue, saturation, luminance);
return '#' + Integer.toHexString(color.getRGB() & 0xffffff | 0x1000000).substring(1);
intgetRandomIntColor()
get Random Int Color
int[] rgb = getRandomRgb();
int color = 0;
for (int c : rgb) {
    color = color << 8;
    color = color | c;
return color;
int[]getRandomRgb()
get Random Rgb
int[] rgb = new int[3];
for (int i = 0; i < 3; i++) {
    rgb[i] = random.nextInt(255);
return rgb;
ColormakeRandomColor()
make Random Color
int R = (int) Math.round(Math.random() * 255);
int G = (int) Math.round(Math.random() * 255);
int B = (int) Math.round(Math.random() * 255);
return new Color(R, G, B);
ColormakeRandomColor()
make Random Color
Random random = new Random();
return new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
ColormakeRandomColor(Color color)
Generates a random Color by scaling each of the red, green and blue components of a specified color with independent random numbers.
if (color == null)
    color = Color.WHITE;
float[] cc = color.getRGBComponents(null);
return new Color(cc[0] * (float) Math.random(), cc[1] * (float) Math.random(),
        cc[2] * (float) Math.random(), cc[3]);
ColormakeRandomColor(Color color, Color darkestColor, int maxAttempts)
Generates a random Color by scaling each of the red, green and blue components of a specified color with independent random numbers.
Color randomColor = makeRandomColor(color);
if (darkestColor == null) {
    return randomColor;
float[] dc = darkestColor.getRGBComponents(null);
float[] rc = randomColor.getRGBComponents(null);
for (int i = 0; i < (maxAttempts - 1) && (rc[0] < dc[0] || rc[1] < dc[1] || rc[2] < dc[2]); i++) {
    rc = randomColor.getRGBComponents(null);
...