In this paper, 5 kinds of generating random numbers are introduced, which are as follows:
Public Enum StringType allstring = 1 ' uppercase and lowercase allnumic = 2 ' Digital str_num = 3 ' uppercase and lowercase + number Str_upper = 4 ' Capital Letter Str_lower = 5 ' Capital Letter End Enum Function generaterandom (ByVal Length as Integer, ByVal s as StringType) A s string Dim strtemp As String = "" Dim constant () As String = Nothing Select case s case stringtype.all Numic strtemp = "0,1,2,3,4,5,6,7,8,9" constant = strtemp. Split (",") case stringtype.allstring strtemp = "A,b,c,d,e,f,g,h,i,j,k,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e, F,d,g,h,i,j,k,l,m,n,p,q,r,s,t,u,v,w,x,x,y,z "constant = strtemp. Split (",") case stringtype.str_lower strtemp = "A,b,c,d,e,f,g,h,i,j,k,m,n,o,p,q,r,s,t,u,v,w,x,y,z" C Onstant = strtemp. Split (",") case stringtype.str_num strtemp = "A,b,c,d,e,f,g,h,i,j,k,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f, d,g,h,i,j,k,l,m,n,p,q,r,s,t,u,v,w,x,x,y,z,0,1,2,3,4,5,6,7,8,9 "constant = strtemp.
Split (",") Case Stringtype.str_upper strtemp = "A,b,c,e,f,d,g,h,i,j,k,l,m,n,p,q,r,s,t,u,v,w,x,y,z" constant = Strte Mp. Split (",") End Select Dim newrandom As System.Text.StringBuilder = New System.Text.StringBuilder (Length) Dim R D as Random = New Random () Dim I as Integer for i = 0 to Length-1 step i + 1 Newrandom.append constant (Rd. Next (constant.
Length-1))) Next return newrandom.tostring () end Function
Public Function Randcode (ByVal N as Integer) as String
Dim Arrchar as Char () = New Char () {"A" C, "B" C, "D" C, "C" C, "E" C, "F" C, _
"G" C, "H" C, "I" C, "J" C, "K" C, "L" C, _
"M" C, "n" C, "P" C, "R" C, "Q" C, "S" C, _
"T" C, "U" C, "V" C, "W" C, "Z" C, "Y" C, _
"x" C, "0" C, "1" C, "2" C, "3" C, "4" C, _
"5" C, "6" C, "7" C, "8" C, "9" C, "A" C, _
"B" C, "C" C, "D" C, " E "C", "F" C, "G" C, _
"H" C, "I" C, "J" C, "K" C "," L "C," M "C, _
" N "C," Q "C," P "C," R "C," T "C," S "C," C ","
W " "C," X "C," Y "C," Z "C}
Dim num As New StringBuilder ()
Dim rnd As New Random (DateTime.Now.Millisecond) for
I As Integer = 0 to n-1
Num. Append (Arrchar (Rnd.[next] (0, arrchar.length)). ToString ())
Next return
Num. ToString () End
Function
Public Function Randcode (ByVal N as Integer) as String
Dim Arrchar as Char () = New Char () {"A" C, "B" C, "D" C, "C" C, "E" C, "F" C, _
"G" C, "H" C, "I" C, "J" C, "K" C, "L" C, _
"M" C, "n" C, "P" C, "R" C, "Q" C, "S" C, _
"T" C, "U" C, "V" C, "W" C, "Z" C, "Y" C, _
"x" C, "0" C, "1" C, "2" C, "3" C, "4" C, _
"5" C, "6" C, "7" C, "8" C, "9" C, "A" C, _
"B" C, "C" C, "D" C, " E "C", "F" C, "G" C, _
"H" C, "I" C, "J" C, "K" C "," L "C," M "C, _
" N "C," Q "C," P "C," R "C," T "C," S "C," C ","
W " "C," X "C," Y "C," Z "C}
Dim num As New StringBuilder ()
Dim rnd As New Random (DateTime.Now.Millisecond) for
I As Integer = 0 to n-1
Num. Append (Arrchar (Rnd.[next] (0, arrchar.length)). ToString ())
Next return
Num. ToString () End
Function
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.