VB.net 生成随机数的小代码

来源:互联网 发布:淘宝城购物中心 编辑:程序博客网 时间:2024/04/30 14:53

    Public Shared Function NewPassword() As String

        Dim PasswordParent As String = "0123456789ABCDENGHJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%&*"

        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