初来乍到,请教怎么给一随机数排序?
有一随机数(共80个),怎样做到定位排序?就是说例如只给第一到第十个排序,第十一到二十个排序。
80个不重复的随机数.rar
(101.15 KB)
初始程序代码如下:
Option Explicit
Option Base 1
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Dim a(1 To 7) As Long
Const Nums = 80 '定义一个常量80
Private Sub Command1_Click()
Dim i, j, n, t, k, l As Long
Dim KLB(Nums) As Long '定义一个变量
Dim s, m As String '定义字符串
t = timeGetTime
Randomize
For i = 1 To Nums 'i = 1 到 80
n = Int(Rnd * Nums) + 1 'n为随机数
If KLB(n) = 0 Then
KLB(n) = n
If n < 10 Then '判断是否是小于10
n = 0 & n '小于10则在前面加0
End If
s = s & n & " " 's = s & n & vbCrLf
Else
i = i - 1
End If
Next i
Text1.Text = s 't = timeGetTime - t 'MsgBox t
End Sub
[此贴子已经被作者于2022-6-17 11:08编辑过]