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 java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Main {
    public static List<Integer> getUniqueIndexList(int limit) {
        List<Integer> randomList = new ArrayList<>();
        for (int length = 0; length < limit; length++) {
            int temp = getRandomIndex();
            if (!isValueExist(temp, randomList)) {
                randomList.add(temp);
            }
        }
        return randomList;
    }

    public static int getRandomIndex() {
        return getRandomNumber(0, 7);
    }

    public static boolean isValueExist(int value, List<Integer> integers) {
        boolean isExist = false;
        for (int integer : integers) {
            if (integer == value) {
                isExist = true;
                break;
            }
        }
        return isExist;
    }

    public static int getRandomNumber(int min, int max) {
        return new Random().nextInt((max - min) + 1) + min;
    }
}