Java tutorial
//package com.java2s; import android.graphics.Color; import java.util.Random; public class Main { private static String lastColor0, lastColor1, lastColor2; private static String[] Colors = { "#F44336", "#E91E63", "#9C27B0", "#673AB7", "#3F51B5", "#2196F3", "#03A9F4", "#00BCD4", "#009688", "#4CAF50", "#8BC34A", "#CDDC39", "#FFEB3B", "#FFC107", "#FF9800", "#FF5722", "#795548", "#9E9E9E", "#607D8B" }; public static int GetRandomColor() { Random random = new Random(); int p = random.nextInt(Colors.length); while (Colors[p].equals(lastColor0) || Colors[p].equals(lastColor1) || Colors[p].equals(lastColor2)) { p = random.nextInt(Colors.length); } lastColor0 = lastColor1; lastColor1 = lastColor2; lastColor2 = Colors[p]; return Color.parseColor(Colors[p]); } }