mdsk.net
当前位置:首页 >> vB产生100以内的随机数 >>

vB产生100以内的随机数

Dim zhi1 as Integer Dim zhi2 as Integer zhi1 =Int(100*Rnd) zhi2 =Int(100*Rnd) Print “结果算式:" & zhi1 & “+" & zhi2 & “=" & zhi1 + zhi2 //把上面代码的过程放到一个按钮事件就可以了. Rnd是会随机生成一个大于等于0小于1的一个随机单精度数,int((最大数-最小数)*Rnd-最小数)

dim a(1 to 100) as double for i = 1 to 100 a(i) = int(rnd * 1000000000 + 1) next i 产生100个1到1000000000的随机整数

Dim a(10) As IntegerMin = 100: Max = 1For i = 1 To 10Randomizea(i) = Int(Rnd(1) * 100 + 1)Label1.Caption = Label1.Caption & Str(a(i))Sum = Sum + a(i)If a(i) > Max Then Max = a(i)If a(i) 评论0 0 0

Private Sub Command1_Click() For i = 1 To 20 Randomize Text1 = Text1 & Space(1) & Int(Rnd * 100 + 1) Next End Sub Private Sub Command2_Click() On Error Resume Next t = Split(Text1, " ") For j = 0 To UBound(t) - 1 If t(j) Mod 2 <> 0 Then Text2 = Text2 & t(j) & Space(1) Next End Sub

楼上的用的是vbscriptrandomizefor i = 1 to 20 a(i)=int(rnd*(100-50+1))+50next i

Private Sub Command1_Click()Dim a(1 To 100) As IntegerDim i As Integer, j As Integer, k As IntegerFor i = 1 To 100 '给数组a一百个元素赋值,并换每行十个数字输出来窗体上 a(i) = Int(Rnd * 101) k = k + 1 Print Tab((k - 1) * 5); a(i); If k = 10 Then

rnd*101表示不能超过101的数,也可以是小数,因为你没有指定一定要整数一定要整数也就是Int(rnd*(100+1))

Randomize '随机数初始化,非常重要,不然产生的随机数不是真正的随机数!!!For i = 1 To 10a (i)= Rnd(1) '产生一个新的随机数,Rnd(1)表示产生一个与上次不同的随机数a(i)=int(a(i)*100+0.5) '把产生的纯小数的随机数转换为100以内的整数Next i 可以吧?请定为最佳答案,如果满意的话..嘻嘻

Private Sub Command1_Click() Dim oushu%, danshu%, sum% oushu = 0 danshu = 0 For i = 1 To 10 Randomize sum = Int(Rnd * 100) If sum Mod 2 = 0 Then oushu = oushu + sum Else danshu = danshu + sum End If Next i Text1.Text = oushu Text2.Text = danshu End Sub 求采纳为满意回答.

int(rnd*100)

网站首页 | 网站地图
All rights reserved Powered by www.mdsk.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com