VB.net随机产生10个小于数字不重复

来源:百度知道 编辑:UC知道 时间:2024/06/24 10:54:27
Dim i As Integer
Dim j(11) As Integer
Randomize()
i = CInt(Int((10 * Rnd()) + 1))
'产生1到10的一个任意值(),然后分别放入j()数组中,要求不能出现重复得数字
不知道怎么实现类似于抽签的功能,希望高手指教!非常之感谢

没装.net , 用vb写的,然后假装.net,你跑一下看看
Dim i As Integer
Dim j As Integer
Dim arr(10) As Integer
Dim iCount As Integer
Dim bFound As Boolean
Randomize()

Do While iCount < 10

i = CInt(Int((10 * Rnd()) + 1))
bFound = False
For j = 0 To 9
If arr(j) = i Then
bFound = True
Exit For
End If

Next

If Not bFound Then
arr(iCount) = i
iCount = iCount + 1
End If
Loop

For j = 0 To 9
Console.WriteLine( arr(j))
Next j

我有个思路,但是我不是做程序的,不知道可行不。

1,先创建2个数组。A数组装数字,0-10;B数组为空。
2,随即取数字,作为A数组的下标,把该数字传递给B数组,作为B0.
3,删掉A数组中该下标数字,并且把该下标以后的数字的下标依次减1.
4,重复2-3.

呵呵,只是自己的想法,也不知道好使不。。。。呵呵。

我不明白你前边的Clnt是什么意思
i=Int(Rnd*10+1)就能产生1-10中的任意值
j(11)=i
通过赋值放入j()中

Private Sub Button1_Click(ByVal sender As System.Object, ByVal