Java Random Color randomColor()

Here you can find the source of randomColor()

Description

Generates and returns a random RGB Color .

License

Open Source License

Return

A random Color .

Declaration

public static java.awt.Color randomColor() 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.concurrent.ThreadLocalRandom;

public class Main {
    /**// w  ww.ja  v a  2 s. c om
     * Generates and returns a random RGB {@code Color}.
     * 
     * @return A random {@code Color}.
     */
    public static java.awt.Color randomColor() {
        return new java.awt.Color(randomInteger(0, 255), randomInteger(0, 255), randomInteger(0, 255));
    }

    /**
     * Generates and returns a pseudorandom integer value between {@code min} 
     * and {@code max} (inclusive).
     * 
     * @param min The minimum range value, inclusive.
     * @param max The maximum range value, inclusive.
     * @return A pseudorandom integer value between {@code min} and {@code max}
     *         arguments(inclusive).
     */
    public static int randomInteger(int min, int max) {
        return ThreadLocalRandom.current().nextInt(min, max + 1);
    }
}

Related

  1. makeRandomColor(Color color, Color darkestColor, int maxAttempts)
  2. randomBrown()
  3. randomColor()
  4. randomColor()
  5. randomColor()
  6. randomColor()
  7. randomColor()
  8. randomColor()
  9. randomColor()