求教VB生成随机数代码

来源:百度知道 编辑:UC知道 时间:2024/09/18 05:17:17
要求生成24个4000~4400的随机数,且个位数为0或5,4000~4150的数占一半以上。
最好用数组生成,最好用过程,因为我要用VB在Word的表格里生成数据。8行,3列。个位数根据精度选择,选择0生成个位数全是0的数,精度选择5个位数可以是0也可以是5
dim a%()
redim a(i,j)
i=8,j=3

private sub sdf(byval x%,byval y%)
dim a(x,y),c,d as integer
static n as integer
xh:
c=rnd*x+1:d=rnd*y+1
if (x-c+1)*(y-d+1)<12 then goto xh
n=0
for i=c to x
for j=d to y
Randomize
xb:
a (i,j)= Int((4150 - 4000 + 1) * Rnd + 4000)
If a(i,j) Mod 5 = 0 Then
n = n + 1
end if
if n<12 then goto xb
print a(i,j);
next j
next i

啊,写不下去了,贴出来只希望能给你一些启发吧。

Dim n As Integer
Private Sub Command1_Click()
n = 0
Randomize
For i = 0 To 1000
a = Int((4150 - 4000 + 1) * Rnd + 4000)
If a Mod 5 = 0 Then
n = n + 1
Print a;
End If
If n = 12 Then
Exit For
End If
Next i
n = 0
For i = 0 To 1000
a = Int((4400 - 4000 + 1) * Rnd + 4000)
If a Mod 5 = 0 Then
n = n + 1
Print a;
End If
If n = 12 Then
Exit For