要求:
 1、毫无规律可寻
 2、从1-30 位长度用户定义
 3、1-9 的数字构成 A-Z 字母
 4、生成速度快,瞬间完成
 5、不重复
望各位高手能告知实现方法,最好有算法的代码。

解决方案 »

  1.   


       网上文章,参考一下:'============================='生成52个1到100的不重复随机数'=============================
    Dim i, j As Long
    Dim ran(1 To 52) As Long
    Dim tNum As Long
    Dim isExist As Boolean
    RandomizeFor i = 1 To 52
        isExist = False
        tNum = Int(100 * Rnd + 1)
        Debug.Print tNum
        For j = 1 To i
            If ran(j) = tNum Then
               isExist = True
               i = i - 1
               Exit For
            End If
        Next
        If isExist = False Then
           ran(i) = tNum
        End If
    NextFor i = 1 To 52
        msg = msg & ran(i) & Space(1)
    Next
    MsgBox msg
      

  2.   

    连写程序加调试用了40分钟,楼主最少应该给我40分吧.Private Sub Command1_Click()
      Dim str1 As String, str2 As String
      Dim i As Integer, j As Integer, num As Long
      Dim n As Integer, str_cnt As Long
      Dim mei() As String
      Dim isexist As Boolean
      n = 30  '随机数的位数
      num = 30 '要生成的随机数的个数
      
      str2 = ""
      str_cnt = 0
      isexist = False
      
    label1: str1 = ""
        Randomize    For j = 1 To n
            i = Int(10 * Rnd)
            str1 = str1 + Str(i)
        Next j
      If str_cnt = 0 Then
        ReDim Preserve mei(str_cnt)
        mei(str_cnt) = str1
        str_cnt = str_cnt + 1
      Else
        For j = 0 To str_cnt - 1
            If str1 = mei(j) Then
                isexist = True
                Exit For
            End If
        Next j
        If isexist = False Then
            
            ReDim Preserve mei(str_cnt)
            mei(str_cnt) = str1
            str_cnt = str_cnt + 1
        End If
      End If
      If UBound(mei) + 1 = num Then
        For j = 0 To str_cnt - 1
            Debug.Print mei(j) + Chr(10) + Chr(13)
        Next j
         
      Else
        GoTo label1
      End If
      
    End Sub