jeudi 1 octobre 2015

How random is Random().nextInt in Java with huge sample size?

I know this is a discussion that has been had to some extent, but I'm particularly interested in very large sample sizes. In my program below, I am iterating around a trillion times (I have done more and less), and the results just do not seem truly random or even good enough for pseudorandom. I've tried to make it very generic for the forum. If I need to go back and put my actual program and results up, I can. Should I be using a different way of getting a random number than what I have below?

for (int i = 0; i < 1000000000; i++) {

        OB1 ob1= ob1List.get(new Random().nextInt(ob1List.size()));
        OB2 ob21= ob2List.get(new Random().nextInt(ob2List.size()));
        OB2 ob22= ob2List.get(new Random().nextInt(ob2List.size()));
        OB3 ob31= ob3List.get(new Random().nextInt(ob3List.size()));
        OB3 ob32= ob3List.get(new Random().nextInt(ob3List.size()));
        OB3 ob33= ob3List.get(new Random().nextInt(ob3List.size()));
}

Each ArrayList contains 50-100 Objects. ob21 and ob22 are selecting from the same list each iteration, and ob31, ob32, and ob33 are selecting from the same list each iteration.

When breaking down the results though, I noticed that particular objects tend to appear more often in a particular variable more than another variable of the same object type. For example, cell 0 from ob2List seems to only appear in ob22, but almost never in ob21. The same is happening for each cell, and for each list. There should be an equally random chance for cell 0 from ob3List(or any of the lists) to appear in ob31, ob32, or ob33. Certain cells are almost always displaying in the same spots though.

My results do seem to be kind of random, but there are just way too many coincidences in what I'm seeing. I figure I'm either not using the Random Class correctly, or the randomness breaks down after millions or billions of iterations.




Aucun commentaire:

Enregistrer un commentaire