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

I know this is a discussion that has been to some extent, but I am particularly interested in very large sample sizes. In my program below, I repeat about a trillion times (I did more and less), and the results just don't seem really random or even good enough for pseudorandom ones. I tried to make it very common for the forum. If I need to go back and deliver my actual program and results, I can. Should I use a different way to get 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 select each iteration from the same list, and ob31, ob32 and ob33 select each iteration from the same list.

, , , , . , 0 ob2List, , ob22, ob21. , . 0 ob3List ( ) ob31, ob32 ob33. .

, , , . , , .

+4
2

new Random() , , . Random .

+3

SecureRandom :

    SecureRandom secureRandom = new SecureRandom();

    OB1 ob1 = null;
    OB2 ob21, ob22 = null;
    OB3 ob31, ob32, ob33 = null;
    int ob1ListSize = ob1List.size();
    int ob2ListSize = ob2List.size();
    int ob3ListSize = ob3List.size();
    for (int i = 0; i < 1000000000; i++) {

        ob1= ob1List.get(secureRandom.nextInt(ob1ListSize));
        ob21= ob2List.get(secureRandom.nextInt(ob2ListSize));
        ob22= ob2List.get(secureRandom.nextInt(ob2ListSize));
        ob31= ob3List.get(secureRandom.nextInt(ob3ListSize));
        ob32= ob3List.get(secureRandom.nextInt(ob3ListSize));
        ob33= ob3List.get(secureRandom.nextInt(ob3ListSize));
    }

, .

+1

Source: https://habr.com/ru/post/1609849/


All Articles