zer0Id0l
zer0Id0l

Reputation: 1444

Default source of randomness in collections.shuffle

In collections.shuffle we can specify Random seed as an argument which I was passing as System.namoTime() so as to ensure that the randomization is different each time.

I wanted to know what is the default source of Randomness for this api?

Upvotes: 2

Views: 571

Answers (1)

Averroes
Averroes

Reputation: 4228

It creates a new Random when you call shuffle method (if there is no previous Random assigned to static r):

private static Random r;

public static void shuffle(List<?> list) {

         if (r == null) {
             r = new Random();
         }
         shuffle(list, r);
     }

You can pry into the code here.

Upvotes: 2

Related Questions