[vb.net] 랜덤(Random)문자 생성 > vb.net

본문 바로가기

vb.net

[기타] [vb.net] 랜덤(Random)문자 생성

회원사진
하나를하더라도최선을
2020-03-17 11:57 8,751 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

등록된 댓글이 없습니다.
게시판 전체검색