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

vB产生0到100的随机数

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

下载附件或窗口放以下控件 List1 Option1 Caption = "最小值" Option2 Caption = "最大值" Text1 Text = "" Command1 Caption = "生成" 查口代码粘帖如下: Option ExplicitPrivate Const ValueLimit As Long = 100 ' 生成的最大数字

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 求采纳为满意回答.

VB6.0可使用Rnd函数和Int函数编写代码生成一个随机的0到100的整数.

Private Sub Command1_Click() Dim n As Integer, a As Variant, i As Integer, j As Integer'Randomize n = 55 'n代表产生多少个随机数 ReDim a(1 To n) For i = 1 To n a(i) = Int(Rnd * 101) j = i - 1 Do While j a(i) = Int(Rnd * 101) + 1 For j = 1 To i - 1 If a(i) = a(j) Then Exit For Next j Loop List1.AddItem a(i) Next i End Sub

Private Sub Command1_Click() Randomize Dim x As Integer For i = 1 To 20 x = Rnd * 101 Print x; If i Mod 10 = 0 Then Print If x > 90 Then big = big + 1 Next i Print Print "大于90的数的个数:"; big Print End Sub

可用冒泡排序法:代码如下:'不重复随机数排序'添加 Command1 Command2 Command3Option Explicit Dim i&, j&, k&, t&, Trec&, Arr&(), RndVal&, TmpVal&, S Private Sub Form_Load() Command1.Caption = "选随机数" Command2.Caption

用冒泡排序方法:option explicitoption base 1dim a(10) as integerdim i as integerdim n as integerprivate sub command1_click()n = n + 1 if n >= 9 then cls n = 0 end iffor i = 1 to 10 a(i) = int(rnd * 100) print a(i);next iprintend subprivate sub

int(rnd*(100+1)+1) 或者 int(100*rnd+1)

Dim X(10)Option ExplicitPrivate Sub Command1_Click() Dim I As Integer 'Randomize Text1.Text = "" For I = 1 To 10'**********found************* '请不要删除该行' X(I) = Int(Rnd * 100) Text1.Text = Text1.Text & Str(X(I)) & " " '加空格以隔开每个数

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