Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有一个这样的数组。
int[] arr = {1,2,3,4,4,5,6,7,8,8,8,1};
我如何洗牌,但所有的值都相等?
洗牌后的示例预期输出:
3,1,1,8,8,8,7,2,4,4,6,5
你可以这样做:
counts
v
counts[v]
var rng = new Random(); arr = arr .GroupBy(i => i) .OrderBy(g => rnd.Next()) .SelectMany(g => g) .ToArray();