vb,产生100个10000以内不重复的随机素数
1首先将1W以内的素数全部找出来
'1万以内所有的素数数量
count1 = 0
For m = 2 To 10000
Dim n As Integer
n = Sqr(m)
For i = 2 To n
If (m Mod i = 0) Then
GoTo aaa
End If
Next i
'求出的素数m保存在素组a
a(count1) = m
count1 = count1 + 1
c(m) = 1
'Print m
aaa:
Next m
2在所有的素数中抽取100个
count2 = 0
While (count2 < 100)
r = Int((count1 + 1) * Rnd)
If (a(r) <> 0) Then '0代表没用过
b(count2) = a(r)
count2 = count2 + 1
a(r) = 0 '变为0代表用过
End If
Wend
有需要源码的小伙伴可以联系我。也欢迎其他小伙伴留言交流学习