Foxtable(狐表)用户栏目专家坐堂 → [求助]随机组合出现重复怎么办?


  共有2235人关注过本帖树形打印复制链接

主题:[求助]随机组合出现重复怎么办?

帅哥哟,离线,有人找我吗?
农村人
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:174 积分:2349 威望:0 精华:0 注册:2015/8/12 15:36:00
[求助]随机组合出现重复怎么办?  发帖心情 Post By: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

以上代码如何杜绝重复?

 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By: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

 回到顶部