Randomize 语句
初始化随机数生成器。语法Randomize [number]可选的 number 参数是 Variant 或任何有效的数值表达式。说明Randomize 用 number 将 Rnd 函数的随机数生成器初始化,该随机数生成器给 number 一个新的种子值。如果省略 number,则用系统计时器返回的值作为新的种子值。如果没有使用 Randomize,则(无参数的)Rnd 函数使用第一次调用 Rnd 函数的种子值。注意 若想得到重复的随机数序列,在使用具有数值参数的 Randomize 之前直接调用具有负参数值的 Rnd。使用具有同样 number 值的 Randomize 是不会得到重复的随机数序列的。Randomize 语句示例
本示例用 Randomize 语句初始化随机数生成器。由于忽略了数值参数, 所以 Randomize 用 Timer 函数的返回值作为新的随机数种子值。Dim MyValue
Randomize ' 对随机数生成器做初始化的动作。MyValue = Int((6 * Rnd) + 1) ' 生成 1 到 6 之间的随机数值。
數據庫中等n條記錄
select top 1 * from table where ID> any (select top n-1 ID from table )
Dim a(100), c(100)
Print
For i = 1 To 10
c(i) = Int(Rnd * 90) + 10
k = i
For j = 1 To k - 1
If c(j) = c(k) Then i = i - 1
Next j
Next i
For i = 1 To 10
Print c(i);
Next i
Private Sub Command1_Click()
Dim a(10)
Dim i, j, count
For i = 0 To 19
100:
a(i) = Int(Rnd * 100 + 1)
For j = 0 To i - 1
If a(i) = a(j) Then GoTo 100
Next
Next
For i = 0 To 19
count = count + 1 / a(i)
Debug.Print countNext
End Sub
Private Sub Command1_Click()
Dim a(10)
Dim i, j, count
For i = 0 To 19
100:
a(i) = Int(Rnd * 100 + 1)
For j = 0 To i - 1
If a(i) = a(j) Then GoTo 100
Next
Next
End Sub
Private Sub Command1_Click()
Dim a(20)
Dim i, j, count
For i = 0 To 19
100:
a(i) = Int(Rnd * 100 + 1)
For j = 0 To i - 1
If a(i) = a(j) Then GoTo 100
Next
Next
End Sub
select top 20 * from tablename order by newid()
for i=0 to 19
select * from table where ID=array(i)
next i
同意: star_five(圣人)
用vb產生隨機數後的快速方面:
dim strArray(19) as string
dim strRange as string
'生成如 '123','54','7','374',....
for i=0 to 19
strRange="'" & strArray(i) & "',"
next
strRange=left(strRange,len(strRange)-1)'去掉最後一個逗號'只用打開一次連接
'select * from YourTable where ID in ('123','54','7','374',....)
strSql="select * from YourTable where ID in (" & strRange & ")"