Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Random;

public class Main {
    public static String getRandomNiceColor() {
        String[] colors = "00CC66,00CC99,00CCCC,00CCFF,00FFCC,33CC66,33CC99,33CCCC,33CCFF,3399CC,339999,663399,666699,6666CC,669999,669966,6699CC,6699FF,66CC99,66CCCC,66CCFF,996699,996666,9999FF,9999CC,99CCCC,99CCFF,99CC99,CC9966,CC9999,CC99CC,CC99FF,CCCC99,CCCCFF"
                .split(",");
        return "#" + colors[randInt(0, colors.length - 1)];
    }

    /**
     * Returns a pseudo-random number between min and max, inclusive.
     * The difference between min and max can be at most
     * <code>Integer.MAX_VALUE - 1</code>.
     *
     * @param min Minimum value
     * @param max Maximum value.  Must be greater than min.
     * @return Integer between min and max, inclusive.
     * @see java.util.Random#nextInt(int)
     */
    public static int randInt(int min, int max) {

        // Usually this can be a field rather than a method variable
        Random rand = new Random();

        // nextInt is normally exclusive of the top value,
        // so add 1 to make it inclusive
        int randomNum = rand.nextInt((max - min) + 1) + min;

        return randomNum;
    }
}