I have the following class:
public class MyClass
{
private Random rand;
private HashSet<Pair<Integer, Integer>> set;
public MyClass()
{
rand = new Random(Double.doubleToLongBits(Math.random()));
set = new HashSet<Pair<Integer, Integer>>();
}
public void doSomething(int len)
{
set.clear();
for (int i = 0; i < 1000; i++)
{
int index = rand.nextInt(len - 1) + 1;
int min = 1 - index;
int max = len - index - 1;
int j = rand.nextInt(max - min + 1) + min;
if (j != 0)
{
set.add(new Pair<Integer, Integer>(index, j));
}
}
}
}
Pair
is a custom class where I can store two integers. The problem is that every time I call doSomething()
the HashSet
contains always the same values.
How is it possible? How can I fix this problem?
EDIT:
this is my Pair: https://stackoverflow.com/a/677248/1395740