[기타] [vb.net] 랜덤(Random)문자 생성
익명
2020-03-17 11:57
4,941
0
-
- 첨부파일 : RandomKeyGenerator.vb (3.7K) - 다운로드
본문
방법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
댓글목록0