none
1---33随机函数 RRS feed

答案

  • 你好!
    这个代码可以产生33个1-33之间不重复的随机数!
    Dim
    result As Integer() = New Integer(32) {}
    For i As Integer = 0 To 32
        result(i) = i + 1
    Next
    For j As Integer = 33 To 1 Step -1
        Dim r As New Random()
        Dim index As Integer = r.[Next](0, j)
        Dim temp As Integer = result(index)
        result(index) = result(j)
        result(j) = temp
    Next
    For i As Integer = 0 To 32
        Console.WriteLine(result(i).ToString())
    Next

    周雪峰
    2009年12月9日 13:31
    版主