假设我有一个包含6个int类型元素的数组。
它看起来像这样
var array = new int [] { 0, 1, 2, 3, 4, 5 };
我如何随机地打乱我的数组,以确保每个索引都有一个新值。
// Bad
// The number at index 3 did not change and still has a value of 3
new int [] { 1, 0, 5, 3, 2, 4 }
// Good:
// All the index have a new value
new int [] { 4, 2, 0, 5, 3, 1 }
我尝试过Shuffle,但有时有些值会有相同的索引位置
https://stackoverflow.com/questions/56569122
复制相似问题