标题: 交流 [打印本页] 作者: 欢欢 时间: 2008-8-1 17:03 标题: 交流 今天匆忙,写了一篇博客
详细见不重复随机数vba(原创)http://hi.baidu.com/huanhuanxiaozhua/blog,为什么有些会数据不全。也可见附件作者: pureshadow 时间: 2008-8-2 00:25
Sub 产生不重复随机整数()
Dim mr As Range
For Each mr In Range("a1:a10")
Do 'do…loop until语句,指循环至loop until后的条件实现即终止
mr = Int(Rnd() * 10 + 1)
Loop Until Application.CountIf(Range("a1:a10"), mr) = 1
Next mr
End Sub
BY 兰色幻想作者: pureshadow 时间: 2008-8-2 00:25
Sub aa()
Range("a1:a65536") = ""
Dim num As Long, arr(1 To 65536) As Long, arr2(1 To 65536, 0) As Long, x As Long
t1 = Timer
For x = 1 To 65536
arr(x) = x
Next x
For x = 1 To 65536
num = Int(Rnd() * (65536 - x) + 1)
arr2(x, 0) = arr(num)
arr(num) = arr(65536 - x + 1)
Next x
Range("a1").Resize(65536) = arr2
MsgBox "运行时间" & Format(Timer - t1, "0.000") & "秒"
End Sub