dimanche 1 mai 2022

Why would you add a random variable to the shuffle method?

I don't understand the use of an additional random inside the shuffle variable. From the examples I've seen so far, there's not benefit to it, or is there? It says that it specifies the source of randomness, however, isn't the shuffle method in itself random? So why would I want to specify it any further?

ArrayList<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(3);
list.add(4);
list.add(5);

//What is the difference?
Collection.shuffle(list);
Collection.shuffle(list, new Random(2));



Aucun commentaire:

Enregistrer un commentaire