Vb6 How do I make a Random String of 0-9 and a-z of x characters

后端 未结 8 1876
無奈伤痛
無奈伤痛 2021-02-14 03:29

Trying to create a random string, x characters in length using 0-9 and a-z/A-Z and can\'t seem to find a good example, any ideas?

8条回答
  •  梦毁少年i
    2021-02-14 03:41

    Function RandomString(cb As Integer) As String
    
        Randomize
        Dim rgch As String
        rgch = "abcdefghijklmnopqrstuvwxyz"
        rgch = rgch & UCase(rgch) & "0123456789"
    
        Dim i As Long
        For i = 1 To cb
            RandomString = RandomString & Mid$(rgch, Int(Rnd() * Len(rgch) + 1), 1)
        Next
    
    End Function
    

    Please be aware that the built-in random number generator is not cryprographically secure so a function like this should not be used to generate passwords.

提交回复
热议问题