Re: Math.random()




Jeff Higgins wrote:



Oops! having just read RedGrittyBrick's & Patricia's comments;
with a size argument of 1,000,000 I get +14 million iterations.
Scratch this one. :(
Thanks.

public static class NoDuplicateListOfRandomIntegers {

private static Random rand = new Random();

public static List<Integer> getRandomList(int size, int low, int high)
{
if(high <= size) {
throw new IllegalArgumentException();
}
Set<Integer> integers = new HashSet<Integer>();
while(integers.size() < size) {
integers.add(rand.nextInt(high - low + 1 ) + low);
}
List<Integer> ret = new ArrayList<Integer>();
ret.addAll(integers);
return ret;
}
}
}




.