在collections.shuffle
中,我们可以指定随机种子作为参数,我将其作为System.namoTime()传递,以确保每次随机化都是不同的。
我想知道这个 api 的默认随机源是什么?
最佳答案
它创建了一个新的 Random
当您调用 shuffle
方法时(如果之前没有分配给 static
r
的 Random
):
private static Random r;
public static void shuffle(List<?> list) {
if (r == null) {
r = new Random();
}
shuffle(list, r);
}
你可以窥探代码here .
关于java - collections.shuffle 中的默认随机源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22962148/