Java Random Color getRandomColor()

Here you can find the source of getRandomColor()

Description

Random Color generator.

License

Open Source License

Return

Color

Declaration

protected static Color getRandomColor() 

Method Source Code

//package com.java2s;
/**/*from   w  w  w  .  j av  a2s. c  om*/
 * Copyright (C) 2000 - 2013 Silverpeas
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * As a special exception to the terms and conditions of version 3.0 of
 * the GPL, you may redistribute this Program in connection with Free/Libre
 * Open Source Software ("FLOSS") applications as described in Silverpeas's
 * FLOSS exception.  You should have received a copy of the text describing
 * the FLOSS exception, and it is also available here:
 * "http://www.silverpeas.org/docs/core/legal/floss_exception.html"
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.awt.Color;

public class Main {
    /*****************************************************************************************
     * Random Color generator.
     * @return Color
     ******************************************************************************************/
    protected static Color getRandomColor() {
        int transparency = (int) getRandomNumber(100, 375);
        if (transparency > 255) {
            transparency = 255;
        }

        return new Color((int) getRandomNumber(255), (int) getRandomNumber(255), (int) getRandomNumber(255),
                transparency);
    }

    /*****************************************************************************************
     * Random number generator.
     * @param maxValue
     * @return double
     ******************************************************************************************/
    public static double getRandomNumber(double maxValue) {
        return Math.random() * maxValue;
    }

    /*****************************************************************************************
     * Random number generator in specified range.
     * @param minValue
     * @param maxValue
     * @return double
     ******************************************************************************************/
    protected static double getRandomNumber(double minValue, double maxValue) {
        return (minValue + (Math.random() * (maxValue - minValue)));
    }
}

Related

  1. getRandomColor()
  2. getRandomColor()
  3. getRandomColor()
  4. getRandomColor()
  5. getRandomColor()
  6. getRandomColor()
  7. getRandomColor()
  8. getRandomColor(boolean useTransparency)
  9. getRandomColor(float offset, float alpha)