How to generate random colors using Java Program?

import java.awt.Color;

public class Randomize{

	public static void main(String[]args){
		System.out.println(randomColor());
		System.out.println(randomColor());
	}

	public static Color randomColor(){
		return new Color(
			randomInRange(0,255),
			randomInRange(0,255),
			randomInRange(0,255)
		);
	}

	public static int randomInRange(int a, int b){
		return (int)(a + (Math.random()*(b-a)));
	}
}
Download

Comments

Popular posts from this blog