Here you can find the source of randomColour(Random random)
public static Color randomColour(Random random)
//package com.java2s; /******************************************************************************* * Copyright 2014-2017 Open Door Logistics Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * 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./*from w w w . j ava 2 s . co m*/ *******************************************************************************/ import java.awt.Color; import java.util.Random; public class Main { public static Color randomColour(Random random) { while (true) { int red = random.nextBoolean() ? random.nextInt(255) : 0; int blue = random.nextBoolean() ? random.nextInt(255) : 0; int green = random.nextBoolean() ? random.nextInt(255) : 0; int sum = red + blue + green; //int diff = Math.abs(red-blue) +Math.abs(red-green) + Math.abs(blue-green); if (sum > 75 && sum < (240 * 3)) { return new Color(red, blue, green); } } // Color col = new Color(0.1f + 0.8f * random.nextFloat(), 0.1f + 0.8f * random.nextFloat(), 0.1f + 0.8f * random.nextFloat()); // return col; } }