Private Sub Command1_Click()
List1.Clear
Randomize (Timer)
Dim a() As Integer, n As Integer, s() As String
n = InputBox("n=")
Label1.Caption = "n=" & n
ReDim a(1 To n)
ReDim s(1 To Permutation(n))
For i = 1 To Permutation(n)
20 For j = 1 To n
10 a(j) = Int(Rnd * n + 1)
For k = 1 To j - 1
If a(k) = a(j) Then GoTo 10
Next k
Next j
For r = 1 To n
s(i) = s(i) + CStr(a(r))
Next r
For q = 1 To i - 1
If s(q) = s(i) Then
s(i) = ""
GoTo 20
End If
Next q
Next i
For i = 1 To Permutation(n) - 1
For j = i + 1 To Permutation(n)
If s(j) < s(i) Then
t = s(i)
s(i) = s(j)
s(j) = t
End If
Next j
Next i
For i = 1 To Permutation(n)
List1.AddItem s(i)
Next i
Label2.Caption = "共计" & List1.ListCount & "种"
End Sub
Private Function Permutation(ByVal n As Integer) As Long
p = 1
For i = 1 To n
p = p * i
Next i
Permutation = p
End Function
本回答被网友采纳