以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]随机组合出现重复怎么办?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=81832)

--  作者:农村人
--  发布时间:2016/3/7 13:52:00
--  [求助]随机组合出现重复怎么办?
Dim a() As String = {"张","林","陈",“王”,“李”}
Dim b() As String = {"建国",“国庆”,“旺财”}
Dim c() As String = {"男","女"}
For Index As Integer = 0 To 10
    Output.Show(a(rand.Next(0,5)) & b(rand.Next(0,3)) & c(rand.Next(0,2)))
Next

以上代码如何杜绝重复?

--  作者:大红袍
--  发布时间:2016/3/7 14:12:00
--  
Dim a() As String = {"张","林","陈","王","李"}
Dim b() As String = {"建国","国庆","旺财"}
Dim c() As String = {"男","女"}
Dim ls As new List(Of String)
For Index As Integer = 0 To 10
    Dim s As String = a(rand.Next(0,5)) & b(rand.Next(0,3)) & c(rand.Next(0,2))
    If ls.Contains(s) = False
        ls.add(s)
        Output.Show(s)
    Else
        index -= 1
    End If
Next