我想要取一个整数数组,其中包含4-8个小于8的整数,并且不要重复的数字,我用以下函数不能避免重复数字的出现,请问有什么好办法能实现预想的要求。我用的是VB6.0Private Function goodsNumber()
Dim goodsCount as Integer
Dim goods() as Integer
Randomize
goodsCount=Int(4*rnd())+3
Redim goods(goodsCount)
For i=0 To goodsCount
goods(i)=Int(8*Rnd())
Next
goodsNumber = goods
End Function
Dim goodsCount as Integer
Dim goods() as Integer
Randomize
goodsCount=Int(4*rnd())+3
Redim goods(goodsCount)
For i=0 To goodsCount
goods(i)=Int(8*Rnd())
Next
goodsNumber = goods
End Function
解决方案 »
- 如何让程序先停止其它所有的操作?
- string型中间插入string
- 在vb里有没有这样的报表控件-打印可以自定义字段
- 用Excel打印资产标签,了解excel的应该不难!
- 帮我看看c写的这个函数如何在vb中声明,急!!!!!
- 怎样申明一个共有的数组????急!!
- 有谁在VB中使用过控件AvViewX 也就是volo view 用于在VB中显示autocad格式文件,好急啊!
- 大家帮帮忙看看我想一定不会难倒你们的!
- 征答:哪里有SP5能够解决DAO及DATA控件访问Access2000问题的官方资料?
- 求助:关于MSFlexGrid查询问题
- 【问】如何取得当前所有基于IE内核的对象实例?
- 【问】如何获得MyIE2或腾讯TE打开的当前网页的源码及网址(网址不知)?
dim vstr as string
Dim goodsCount as Integer
Dim goods() as Integer
Randomize
vstr="12345678"
vstr=mid(vstr,Int(3*rnd()),Int(4*rnd())+3)
goodsCount =len(vstr)
Randomize
redim goods(goodsCount)
do
i=Int(goodscount*rnd())
goods(i)= mid(vstr ,i,1)
vstr=left(vstr,i) & right(vstr,len(vstr)-i)
loop until vstr=""
goodsNumber = goods
End Function
dim vstr as string
Dim goodsCount as Integer
Dim goods() as Integer
Randomize
vstr="12345678"
vstr=mid(vstr,Int(3*rnd()),Int(4*rnd())+3)
goodsCount =len(vstr)
Randomize
redim goods(goodsCount)
do
i=Int(len(vstr)*rnd())
goods(i)= mid(vstr ,i,1)
vstr=left(vstr,i-1) & right(vstr,len(vstr)-i)
loop until vstr=""
goodsNumber = goods
End Function
Dim goodsCount As Integer
Dim goods() As Integer
Dim used(8) As Boolean
Randomize
goodsCount = Int(4 * Rnd()) + 3
ReDim goods(goodsCount)
For i = 0 To goodsCount
goods(i) = Int((8 - i) * Rnd())
j = 0
Do While j <= goods(i)
If used(j) Then goods(i) = goods(i) + 1
j = j + 1
Loop
used(goods(i)) = True
Next
goodsNumber = goods
End Function
Dim goodsCount As Integer
Dim goods() As Integer
Randomize
vstr = "1234567"
goodsCount = Int(3 * Rnd()) + 4
Randomize
ReDim goods(goodsCount - 1)
i = 0
Do
Randomize
j = Int((Len(vstr) - 1) * Rnd()) + 1
goods(i) = Mid(vstr, j, 1)
vstr = Left(vstr, j - 1) & Right(vstr, Len(vstr) - j)
i = i + 1
Loop Until i >= goodsCount