I have the following code to create a random series of a numbers from 0 to a given amount.
ArrayList<Integer> places = new ArrayList<Integer>();
for (int cnt = 0; cnt < NUMBER; cnt++) {
int place = (int)(random.nextDouble()*places.size());
places.add(place , new Integer(cnt));
}
I use this code in a method and then I run this method for about 1000 times for statistics purposes.
My problem is that created series is the same for all of the 1000 time.
Every time that I run the sequence is different, but same for all of the for values.
What should I do? Is there a method like srand() in C++?
Your algorithm seems flawed if you are trying to generate an array with numbers
0 ... NUMBER-1in random order. Consider: