Here you can find the source of distinctInts(int from, int to, int number)
Parameter | Description |
---|---|
from | a parameter |
to | a parameter |
number | a parameter |
public static int[] distinctInts(int from, int to, int number)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Random; public class Main { private static final Random rand = new Random(); /**// w w w . j a v a2 s . com * Returns from the range of [from, to] (inclusive). "Number" amount of distinct integers. * @param from * @param to * @param number * @return */ public static int[] distinctInts(int from, int to, int number) { if (from >= to) throw new IllegalArgumentException("From cannot be larget than to!"); List<Integer> lst = new ArrayList<Integer>(); for (int i = from; i <= to; i++) lst.add(i); Collections.shuffle(lst, rand); int[] ret = new int[number]; for (int i = 0; i < number; i++) ret[i] = lst.get(i); return ret; } }