Unity C#中是否有一种简单的方法可以在字符串中对字母进行洗牌?这是为了创建一个字符串的洗牌版本。
答案 0 :(得分:-1)
Google Fisher-Yates,你会发现这一点。
To shuffle an array a of n elements (indices 0..n-1):
for i from n − 1 downto 1 do
j ← random integer with 0 ≤ j ≤ i
exchange a[j] and a[i]
这应该很容易转化为c#
答案 1 :(得分:-1)
按不可预测的内容订购字符串
var oldString = "shuffle";
var shuffled = new string(oldString.OrderBy(x => Guid.NewGuid()).ToArray());
//shuffled = "feflhus"