天天看點

VB.net 生成随機數的小代碼

    Public Shared Function NewPassword() As String

        Dim PasswordParent As String = "[email protected]#$%&*"

        Dim RetVal As String = ""

        Dim Rnd As Random = New Random(System.DateTime.Now.Millisecond)     '通過日期産生随機數

        For i As Integer = 0 To 8

            Dim iRandNum As Integer = Rnd.Next(PasswordParent.Length)

            RetVal += PasswordParent(iRandNum)                              '每次生一個随機數加入數組

        Next i

        Return RetVal

    End Function