Here you can find the source of randomLongsNonDuplicates(final long count, final long min, final long max)
public static long[] randomLongsNonDuplicates(final long count, final long min, final long max)
//package com.java2s; //License from project: Apache License import java.util.LinkedHashSet; import java.util.Random; import java.util.Set; import java.util.concurrent.ThreadLocalRandom; public class Main { public static long[] randomLongsNonDuplicates(final long count, final long min, final long max) { ThreadLocalRandom rng = ThreadLocalRandom.current(); // Note: use LinkedHashSet to maintain insertion order //TODO not efficient Set<Long> generated = new LinkedHashSet<>(); while (generated.size() < count) { Long next = randLong(rng, min, max); generated.add(next);//from ww w .j ava2s . c om } return generated.stream().mapToLong(i -> i).toArray(); } private static long randLong(Random random, long min, long max) { //TODO swith impl return min + ((long) (random.nextDouble() * (max + 1 - min))); } }