vb中随机函数Rnd(x)的问题?
OptionExplicitOptionBase1PrivateSubForm_Click()DimA()AsInteger,B(2,3)AsInteger,VAsVar...
Option Explicit
Option Base 1
Private Sub Form_Click()
Dim A() As Integer, B(2, 3) As Integer, V As Variant
Dim I As Integer, J As Integer
Print "B数组各元素值:"
For I = 1 To 2
For J = 1 To 3
B(I, J) = Int(10 * Rnd)
Print B(I, J);
Next J
Print
Next I
V = B
Print "V各元素值:"
For I = 1 To UBound(V, 1)
For J = 1 To UBound(V, 2)
Print V(I, J);
Next J
Print
Next I
A = B
Print "A数组各元素值:"
For I = 1 To UBound(A, 1)
For J = 1 To UBound(A, 2)
Print A(I, J);
Next J
Print
Next I
Print "A的维界:"
Print "第一维上界"; LBound(A, 1); "第一维上届"; UBound(A, 1)
Print "第二维上届"; LBound(A, 2); "第二维上届"; UBound(A, 2)
Exit Sub
End Sub
为什么输出地结果总是不变,不是用了Rnd函数吗? 展开
Option Base 1
Private Sub Form_Click()
Dim A() As Integer, B(2, 3) As Integer, V As Variant
Dim I As Integer, J As Integer
Print "B数组各元素值:"
For I = 1 To 2
For J = 1 To 3
B(I, J) = Int(10 * Rnd)
Print B(I, J);
Next J
Next I
V = B
Print "V各元素值:"
For I = 1 To UBound(V, 1)
For J = 1 To UBound(V, 2)
Print V(I, J);
Next J
Next I
A = B
Print "A数组各元素值:"
For I = 1 To UBound(A, 1)
For J = 1 To UBound(A, 2)
Print A(I, J);
Next J
Next I
Print "A的维界:"
Print "第一维上界"; LBound(A, 1); "第一维上届"; UBound(A, 1)
Print "第二维上届"; LBound(A, 2); "第二维上届"; UBound(A, 2)
Exit Sub
End Sub
为什么输出地结果总是不变,不是用了Rnd函数吗? 展开
展开全部
是10*rnd()
你漏加()了吧
还有最好加一句randomize
否则每次运行的随机数是一样的
你漏加()了吧
还有最好加一句randomize
否则每次运行的随机数是一样的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
加一个随机种子:
Randomize
B(I, J) = Int(10 * Rnd)
Randomize
B(I, J) = Int(10 * Rnd)
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Rnd 是函数 后面有括号
应该是 10*RND()
记得每次使用前初始化
应该是 10*RND()
记得每次使用前初始化
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询