把1到100随机排序
发布网友
发布时间:2022-05-12 22:48
我来回答
共4个回答
热心网友
时间:2023-07-20 21:17
Private Sub Command1_Click()
Dim A(1 To 100) As Integer
For I = 1 To 100
A(I) = I
Next
Randomize
Dim Deep As Integer
Deep = 500 '随机的深度
For I = 1 To Deep
M = Int(Rnd * 100) + 1
N = Int(Rnd * 100) + 1
If M <> N Then
T = A(M): A(M) = A(N): A(N) = T
End If
Next
For I = 1 To 100
s = s & A(I) & IIf(I Mod 10 = 0, vbCrLf, String(3 - Len(CStr(A(I))), " "))
Next
Text1.Text = s
End Sub
热心网友
时间:2023-07-20 21:18
'这是一个函数,随机生成iCount个min到max中不重复的数放到数组k()里
Private Sub iRnd(iMin As Long, iMax As Long, iCount As Long, k() As Long)
ReDim k(iCount - 1) As Long
For i = 0 To iCount - 1
DoEvents
Randomize
k(i) = Int(Rnd * (iMax - iMin + 1)) + iMin
For j = 0 To i - 1
DoEvents
If k(i) = k(j) Then i = i - 1: Exit For
Next
Next
End Sub
热心网友
时间:2023-07-20 21:18
Private Sub Form_Click()
Dim a(99) As Integer
For i = 0 To 99
a(i) = i + 1
Next i
Randomize
For i = 0 To 99
x = Int(Rnd * 100)
y = Int(Rnd * 100)
t = a(x): a(x) = a(y): a(y) = t
Next i
For i = 0 To 99
If i Mod 10 = 0 Then Print
Print Format(a(i), "@@@@");
Next i
End Sub
热心网友
时间:2023-07-20 21:19
Dim A(1 To 100) As Integer, i As Integer, j As Integer, k As Integer, B(1 To 100) As Integer
For i = 1 To 100
A(i) = i
Next i
Randomize
For i = 1 To 100
j = Int(Rnd() * (101 - i) + 1)
B(i) = A(j)
For k = j To (101 - i)
If k <> 100 Then A(k) = A(k + 1)
Next k
Next i
For i = 1 To 100
Debug.Print B(i);
If i Mod 10 = 0 Then Debug.Print
Next i