방법1. RandomKeyGenerator.vb 클래스를 추가하고 아래 함수를 사용하면 됩니다.?
Private Function RandomString(ByVal KeyChars As Integer) As String
Dim KeyGen As New RandomKeyGenerator
KeyGen.KeyLetters = "abcdefghijklmnopqrstuvwxyz"
KeyGen.KeyNumbers = "0123456789"
KeyGen.KeyChars = KeyChars
Return KeyGen.Generate()
End Function
방법2.
Imports System.Text
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MsgBox(RandomString(10))
End Sub
Public Function RandomString(ByVal strLen As Integer) As String
Dim S As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
Dim SB As New StringBuilder
Dim R As New Random
For i As Integer = 1 To strLen
SB.Append(S.Substring(R.Next(0, S.Length), 1))
Next
Return SB.ToString()
End Function
End Class