Colors { @ColorInt public static int random(final boolean randomAlpha) { final Random rand = new Random(); return Color.argb( randomAlpha ? rand.nextInt(COMPONENT_VALUE_MAX + 1) : COMPONENT_VALUE_MAX, rand.nextInt(COMPONENT_VALUE_MAX + 1), rand.nextInt(COMPONENT_VALUE_MAX + 1), rand.nextInt(COMPONENT_VALUE_MAX + 1) ); } private  Colors(); @ColorInt static int withAlpha(@ColorInt final int color, @FloatRange(from = 0, to = 1) final float alphaRatio); @ColorInt static int withAlpha(@ColorInt final int color, @IntRange(from = COMPONENT_VALUE_MIN, to = COMPONENT_VALUE_MAX) final int alpha); @ColorInt static int blend(@ColorInt final int first, @ColorInt final int second); @SuppressWarnings("UnnecessaryLocalVariable") @ColorInt static int blend(@ColorInt final int first, @ColorInt final int second, @FloatRange(from = 0, to = 1) final float blendingRatio); @ColorInt static int brighter(@ColorInt final int color, @FloatRange(from = 0, to = 1) final float fraction); @ColorInt static int darker(@ColorInt final int color, @FloatRange(from = 0, to = 1) final float fraction); @ColorInt static int random(final boolean randomAlpha); @NonNull static String hexName(@ColorInt final int color); @NonNull static String hexName(@ColorInt final int color, final boolean withAlpha);  }
@Test public void testRandom() { final int colorsCount = 1000; final List<Integer> colors = new ArrayList<>(); for (int i = 0; i < colorsCount; i++) { final int randomColor = Colors.random(i % 2 == 0); assumeFalse(colors.contains(randomColor)); colors.add(randomColor); } }