这是代码:
private static StringBuilder MakeRandomwords(string theWord)
{
var jumbleSb = new StringBuilder();
jumbleSb.Append(theWord);
int lengthSb = jumbleSb.Length;
for (int i = 0; i < lengthSb; ++i)
{
int index1 = (RandomGen.Next() % lengthSb);
int index2 = (RandomGen.Next() % lengthSb);
Char temp = jumbleSb[index1];
jumbleSb[index1] = jumbleSb[index2];
jumbleSb[index2] = temp;
}
return jumbleSb;
}
这是我用来构建乱码的列表:
private void GetText()
{
_lengthaboveone = new List<string>();
for (int i = 0; i < _words.Count; i++)
{
string word = _words[i];
if (word.Length < 4) continue;
string first = word.Substring(0, 1);
string last = word.Substring(word.Length - 1, 1);
string middle = word.Substring(1, word.Length - 2);
_lengthaboveone.Add(middle);
_words[i] = first + MakeRandomwords(middle) + last;
}
_scrambledWords = _words;
}
最后,List _scrambledWords 在每个索引中包含超过 1000 个字符串一个单词的字符串,其中大部分是加扰的,但其中一些与原始字符串中的相同。
问题是我的 MakeRandomwords 是否有问题?莫非是把字打乱了,就乱成原来的样子了?所以也许我需要在代码中添加一些东西来保持对单词的加扰,直到单词被加扰,直到单词被加扰为止?