产生不重复的随机数
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
产生不重复的随机数
Sub zjx()
For i = 1 To 36 '如果改成200就是在1-200里选数 Cells(i, 1) = i Next
c = [e2000].End(xlUp).Row Randomize
a = 36 '上面改成200后这边也得更改成200 For i = 5 To 10
b = Int(a * Rnd() + 1) Cells(
c + 1, i) = Cells(b, 1)
Cells(b, 1).Delete Shift:=xlUp
a = a - 1
Next
End Sub
自己做个按钮,每点击一次增加一行。(vba,宏)
看我的吧
Sub Comm()
Randomize Timer
Dim c(100) As Byte
For i = 1 To 100'产生100个随机数
c(i) = i
Next
k = 100
Do While l < 100
r = Int(Rnd() * k) + 1‘随机数的范围
aa = c(r)
c(r) = c(k)
c(k) = aa
k = k - 1
l = l + 1
cells(l,1)=aa
Loop
End Sub
Sub suiji()
c = Cells(65500, 5).End(xlUp).Row Randomize a = Second(Now())
For i = 5 To 10
line1:
b = Second(Now())
x = Abs(Int(b * Rnd() - a - 7))
If x < 1 Then
GoTo line1
End If
With Range(Cells(c + 1, 5), Cells(c + 1, 10)) Set cc = .Find(x, lookat:=xlWhole)
If cc Is Nothing Then
Cells(c + 1, i) = x
Else
GoTo line1
End If
End With a = a - 9 Next
End Sub