Public Class Form2
    Private Function getRandom(ByVal iCnt As Integer) As String    ' iCnt字符串个数 
        Dim allChar As String = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,0,1,2,3,4,5,6,7,8,9"
        Dim allCharArray As String() = allChar.Split(","c)
        Dim randomCode As String = ""
        Dim temp As Integer = -1
        Dim random As New Random()
        For i As Integer = 0 To iCnt - 1
            Dim t As Integer = random.Next(62)
            randomCode += allCharArray(t)
        Next
        Return randomCode
    End Function
    Private Function GenerateCheckCode(ByVal codeCount As Integer) As String
        ' codeCount字符串个数 
        Dim number As Integer
        Dim code As Char
        Dim checkCode As String = String.Empty
        Dim random As System.Random = New Random()
        For i As Integer = 0 To codeCount - 1
            number = random.Next()
            If number Mod 2 = 0 Then
                code = Chr(48 + (number Mod 10))
            Else
                code = Chr(65 + (number Mod 26))
            End If
            checkCode += code.ToString()
        Next
        Return checkCode
    End Function
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '随机字符产生
        Dim Rnd1 As Random = New Random()
        'b = Rnd1.Next(10, 100)
        Dim t1 As Integer = Rnd1.Next(97, 123)
        Dim c As Char = Chr(t1)
        Me.Text = GenerateCheckCode(4)

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim rdm As New Random()
        Dim al As New ArrayList()
        al = New ArrayList(10)
        Dim t As Integer = 0
        While al.Count < 10
            t = rdm.Next(1, 100)
            If Not al.Contains(t) Then
                al.Add(t)
            End If
        End While
        al.Sort()
        Dim arr1 As Integer() = New Integer(al.Count - 1) {}
        arr1 = al.ToArray(GetType(Integer))
        For Each t In arr1
            Me.Text = Me.Text & "|" & t.ToString()
        Next
    End Sub
End Class