Java Random Color getRandomHexColor()

Here you can find the source of getRandomHexColor()

Description

get Random Hex Color

License

Apache License

Declaration

public static String getRandomHexColor() 

Method Source Code

//package com.java2s;
/*//ww  w . j  a va  2 s.c om
 ************************************************************************************
 * Copyright (C) 2001-2011 encuestame: system online surveys Copyright (C) 2011
 * encuestame Development Team.
 * Licensed under the Apache Software License version 2.0
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to  in writing,  software  distributed
 * under the License is distributed  on  an  "AS IS"  BASIS,  WITHOUT  WARRANTIES  OR
 * CONDITIONS OF ANY KIND, either  express  or  implied.  See  the  License  for  the
 * specific language governing permissions and limitations under the License.
 ************************************************************************************
 */

import java.util.Random;

public class Main {
    /**
     *
     * @return
     */
    public static String getRandomHexColor() {
        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;
    }

    /**
     * get random hex
     *
     * @return int
     */
    private static String getRandomHex() {
        Random random = new Random();
        String[] hex = new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E",
                "F" };
        Integer randomNum = random.nextInt(hex.length);
        String sHex = hex[randomNum];
        return sHex;
    }
}

Related

  1. getRandomColor(boolean useTransparency)
  2. getRandomColor(float offset, float alpha)
  3. getRandomColor(int saturationRandom, float luminance)
  4. getRandomColorInString()
  5. getRandomColour()
  6. getRandomHexColor()
  7. getRandomIntColor()
  8. getRandomRgb()
  9. makeRandomColor()