Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.Color; import java.util.Random; public class Main { public static int randomColor() { Random random = new Random(); int r = random.nextInt(256); int g = random.nextInt(256); int b = random.nextInt(256); double color_perception = 1 - (0.299 * r + 0.587 * g + 0.114 * b) / 255; if (color_perception > 0.4) { return Color.argb(255, r, g, b); } else { return randomColor(); } } }