Java Random Color randomColor()

Here you can find the source of randomColor()

Description

random Color

License

Open Source License

Declaration

public static int randomColor() 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Random;

public class Main {
    private static final Random RANDOM = new Random();

    public static int randomColor() {
        return RANDOM.nextInt(256);
    }/*  w  w w  . j  a  va2  s.  c  o m*/

    public static int randomColor(int from, int to) {
        assertColor(from);
        assertColor(to);

        if (from > to) {
            throw new IllegalArgumentException("From can't be larger than to");
        }
        if (from == to) {
            return from;
        } else {
            return RANDOM.nextInt(to - from + 1) + from;
        }
    }

    public static void assertColor(int color) {
        if (color < 0 || color > 255) {
            throw new IllegalArgumentException("Color outside of range 0 - 255");
        }
    }
}

Related

  1. makeRandomColor()
  2. makeRandomColor(Color color)
  3. makeRandomColor(Color color, Color darkestColor, int maxAttempts)
  4. randomBrown()
  5. randomColor()
  6. randomColor()
  7. randomColor()
  8. randomColor()
  9. randomColor()