我的代码从txt文件中获取单词列表并随机选择单词。但是,同一个词可以出现多次,我需要知道如何阻止这种情况的发生?如何更改我的代码工作一定次数?
下面是代码:
Dim aryName As String() = Nothing
aryName = File.ReadAllLines(Application.StartupPath & "\Random\fnames.txt")
Dim randomWords As New List(Of String)
For i = 0 To aryName.Length - 1
If randomWords.Contains(aryName(i)) = False Then
randomWords.Add(aryName(i))
End If
Next
Dim random As New Random
Label2.Text = (randomWords(random.Next(0, randomWords.Count - 1)).ToString)
也许这可能会奏效,虽然它在英语,而不是代码:(
if label1.text is changed then
Get label1.text
if label.text becomes this word again then
run the random code
end if
end if
您的意思是说输入列表中有重复或者多次选择了相同的单词吗? – ChrisF 2011-12-23 16:27:09
那么,随机单词多次出现在aryName中? – Aaron 2011-12-23 16:27:32
你想要一个洗牌方法吗? – Cobold 2011-12-23 16:28:56