Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.graphics.Color;
import java.util.Random;

public class Main {
    /**
     * Generates an array of random colors given the number of colors to create.
     * @param numOfColors, the number of colors to create.
     * @return an array of the random colors.
     */
    public static int[] getRandomColors(int numOfColors) {
        Random random = new Random();
        int colors[] = new int[numOfColors];
        for (int i = 0; i < numOfColors; i++) {
            int r = random.nextInt(256);
            int g = random.nextInt(256);
            int b = random.nextInt(256);

            if ((r + g + b) > 450) {
                r = 110;
                b = 110;
                g = 110;
            }
            colors[i] = Color.rgb(r, g, b);
        }
        return colors;
    }
}