mdsk.net
当前位置:首页 >> vB生成100个随机数 >>

vB生成100个随机数

dim a(1000) as longdim i as longfor i=0 to 999 a(i)=int(rnd*99999999) doeventsnext

因为你Text1.text=Int(rnd*100+1)是赋值语句,每次讲产生的随机数赋值给文本框,所以文本框每次显示一个数值,如果要保留文本框前面的数值,并且每次点击多显示一个则要用到静态变量 private sub Command1_Click dim n as static '定义一个静态变量n,能够保留上一次调用的值 n=n & Int(rnd*100+1) &" " '产生一个随机数,连接到n变量后,再连接一个“ ”空格字符,好看一些 Text1.text =n end sub 或者你把n定义在窗体的通用声明处,作为窗体级变量,Dim n as string

dim Num(100) as integer dim TJ(10) as integer dim temp as integer for i=1 to 100 num(i-1)=int(99*rnd()) temp=val(right(str(num(i-1)),1)) TJ(temp)=tj(temp)+1 next i for i=0 to 99 form1.print num(i-1) next i for i=0 to 9 form1.print "各位数字为" & i & "的数字共有:" & tj(i) & "个";next i

Private Sub Command1_Click()ClsDim a(100) As LongFor i = 1 To 100Randomizea(i) = Int(Rnd * 100) + 1Next iFor i1 = 1 To 99For i2 = i1 To 100If a(i1) < a(i2) Thenb = a(i1)a(i1) = a(i2)a(i2) = bEnd IfNext i2, i1For i = 1 To 100Print a(i);If i Mod 10 = 0 Then PrintNext iPrintPrint "最大值"; a(1)End Sub

VB生成抄1-100之间的随机整数,可以使袭用系统自带的Rnd()方法进行2113实现,代码如下:Private Sub Command_Click() Dim MyValue //定义一个随机数5261 MyValue = Int((100 * Rnd) + 1) //rnd()函数生成随4102机数 Print MyValue //打印出这个随机数 End Sub Private Sub Form_Load() Randomize //初始化随机数生成器1653 End Sub

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

首先介绍Int和Randomize.Int语法格式:Int((upperbound - lowerbound + 1) * Rnd + lowerbound)这里,upperbound 是随机数范围的上限,而 lowerbound 则是随机数范围的下限. 为了在不同的运行时能得到不同的随机整数,可以在使用Rnd函

'方法1,不是你的方法,呵呵,直接产生10个随机数记性排列,谁知道是怎么产生的 ,呵呵.randomize dim a(9) for i=0 to 9 a(i)=int(rnd*300+101) next i for j = 0 to 8 for k = 0 to 8 - j if a(k) > a(k + 1) then t = a(k) a(k) = a(k + 1) a(k + 1) = t end if next

Dim a(0 To 49) As StringFor i = 0 To 49a(i) = Int(Rnd() * 100)If a(i) < 10 Then a(i) = "0" + a(i)Print a(i)Next

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