dimanche 22 février 2015

Java object Random always returns error: "Random.nextInt(int) line: not available"

I am currently writing a program for school to test the efficiency of different sorting algorithms. When trying to create arrays of random numbers, the Random object always gives an error.


arrays is type ArrayList<ArrayList<Integer>> and is a set of the arrays I test


numTrials is type int and is the number of trials per size of array (I am testing different array sizes at different powers of 10)


This is my code to fill the arrays right now:



Random randGen = new Random();

for(int i = 0; i < arrays.size(); i++)
{
for(int j = 0; j < Math.pow(10.0, i / numTrials); j++)
{
arrays.get(i).set(j, randGen.nextInt(i));
}
}


I tried seeding as well by calling randGen.setSeed(System.currentTimeMillis()) but the error still showed up every time.





Aucun commentaire:

Enregistrer un commentaire