标签:实现 oid 随机 swa random shuffle tin dom and
public <T> void shuffle(List<T> list) { int size = list.size(); Random random = new Random(); for(int i = 0; i < size; i++) { int randomPos = random.nextInt(size); T temp = list.get(i); list.set(i, list.get(randomPos)); list.set(randomPos, temp); } }
public <T> void shuffle(List<T> list) { int size = list.size(); Random random = new Random(); for(int i = 0; i < size; i++) { int randomPos = random.nextInt(size); Collections.swap(list, i, randomPos); } }
Collections.shuffle实现
public <T> void shuffle(List<T> list) { Collections.shuffle(list); }
标签:实现 oid 随机 swa random shuffle tin dom and
原文地址:https://www.cnblogs.com/remember-forget/p/9815527.html