绝对最优算法!!!<br>由数组取部分(全部)不重复随机数组的算法:<br>[代码最简洁,变量最少,循环次数最少,有能改一字者,赏千金!!!<br><br>rivate Sub 命令0_Click()<br>Const AllCount = 100, GetCount = 50<br>Dim a(1 To AllCount) As Long<br>Dim i, Temp, RndNum As Long<br>'赋值给数组<br>For i = 1 To AllCount<br>a(i) = i<br>Next<br>'给数组随机排序<br>For i = 1 To GetCount<br>RndNum = Int(Rnd * (AllCount + 1 - i)) + i '产生一个i到100之间的随机数<br>Temp = a(i)<br>a(i) = a(RndNum)<br>a(RndNum) = Temp<br>Debug.Print a(i)<br>Next i<br>End Sub<br><br>
[此贴子已经被作者于2006-9-22 14:25:22编辑过]
|