Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.ArrayList;
import java.util.Random;

public class Main {

    public static int[] randNum(int num, int min, int max) {
        ArrayList<Integer> list = new ArrayList<Integer>();
        Random rand = new Random();
        while (true) {
            int rm = (rand.nextInt(max - min) + min);
            if (!list.contains(rm)) {
                list.add(rm);
                if (list.size() >= num)
                    break;
            }
        }
        int result[] = new int[num];
        for (int i = 0; i < list.size(); i++) {
            result[i] = list.get(i);
        }
        return result;
    }
}