取随机隐者数可以用 Random 类。
创新互联从2013年成立,先为双桥等服务建站,双桥等地企业,进行企业商务咨询服务。为双桥企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
给定10个数的话,可以把这10个数放在一个余镇数组里,然后取0~9的范围内的随机数,用它当竖携粗数组下标取数组成员即可。
方法名称:next();功能描述:返回一个0~2147483647之间的整数
方法名称:next(i);功能描述:返回一个0~i之间的整和罩铅数
方法名称:next(i,j);功能描述:返回一个闷凯i~j之间的整数
方法名称:Nextdouble();唤好功能描述:返回一个0~1之间的随机小数
================
使用方法:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim rand = New System.Random()
MsgBox(rand.next().ToString())
End Sub
==========================
产生N个不同数的话,我给你个我写的VB的代码,你稍微改下:
产生0-10的数:
Private Sub Command1_Click()
Randomize
Dim a(10) As Long
n = 10
For i = 0 To n
a(i) = Int(Rnd() * (n + 1))
For j = 0 To i - 1
If a(i) = a(j) Then
i = i - 1
Exit For
End If
Next
Next
For i = 0 To n
Print a(i)
Next
End Sub
Private Sub Command1_Click()
Dim a(1 To 100) As Integer
Dim i As Integer, j As Integer, k As Integer
For i = 1 To 100 '给数组a一百个元素野雹赋值漏脊乱,并换每行十个数字输出返档来窗体上
a(i) = Int(Rnd * 101)
k = k + 1
Print Tab((k - 1) * 5); a(i);
If k = 10 Then k = 0: Print
Next i
For i = 100 To 2 Step -1 '用冒泡排序法对数组进行排序
For j = 1 To i - 1
If a(j) a(j + 1) Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next j
Next i
For i = 1 To 100 '输出排好序的数组
k = k + 1
Print Tab((k - 1) * 5); a(i);
If k = 10 Then k = 0: Print
Next i
End Sub
'项目:VB中产生在一定正整数范围内的唤清不重复的随启没机数'作者:qq15495835Private Sub Command1_Click() Max = 100 '随机数上限值 Min = 1 '随机数下限值 Amount = 10 '产生号码数量(数量值应小于随机数上限值-随机数下限值)否则会产生死循环 ReDim a(Amount) Randomize For i = 0 To Amount a(i) = Int((Max - Min + 1) * Rnd + Min) For j = 0 To i If i j And a(i) = a(j) Then i = i - 1 Next Next Text1 = Join(a, vbCrLf)End Sub'请采纳参考!谢谢!悄链纳