mdsk.net
当前位置:首页 >> vB产生50个60到100随机数 >>

vB产生50个60到100随机数

private sub command1_click()dim a(1 to 50) as integerdim n as integerrandomizefor i = 1 to 50a(i) = int(rnd * 100 + 1)if a(i) 评论0

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

Private Sub Command1_Click()Dim a(1 To 50) As IntegerDim n As IntegerRandomizeFor i = 1 To 50a(i) = Int(Rnd * 100 + 1)If a(i) 评论0 0 0

Private Sub Command1_Click() Dim i As Integer, n As Integer, m As Integer For i = 1 To 50 n = Int(1 + Rnd * 100) If n < 60 Then Print n; m = m + 1 End If If m Mod 10 = 0 Then Print NextEnd Sub

这个例子可以解决你的问题:Private Sub Command1_Click()Dim i As Integeri = Int((100 - 50 + 1) * Rnd + 50)Print iEnd Sub为了生成某个范围内的随机整数,可使用以下公式:Int((upperbound - lowerbound + 1) * Rnd + lowerbound)这里,upperbound 是随机数范围的上限,而 lowerbound 则是随机数范围的下限.

Private Sub Command1_Click() Dim i, max, min, s As Integer max = 0 min = 100 s = 0 Dim a(30) As Integer Text1.Text = "" Text2.Text = "" Text3.Text = "" Randomize Now For i = 1 To 30 a(i) = Int((100 - 50 + 1) * Rnd + 50) If max If min > a(i)

Private Sub Form_Click() Dim i, j, t, a(1 To 50) Cls Randomize Print "50个随机数:" For i = 1 To 50 a(i) = 1 + Int(100 * Rnd) Print a(i); If i Mod 10 = 0 Then Print Next Rem 用冒泡法排序 For i = 1 To 49 For j = 1 To 50 - i If a(j) > a(j + 1) Then t = a(j

whomi1978写的很好,完全能够达到你的要求.但是,他犯了一个很小的错误:他的代码只能产生60-99的随机数,绝不会出现100,既然题目要求60到100,则必须用:a=60+int(rnd*41)这个绝不能含糊.

option base 1 private sub command1_click() dim arr(20) as integer, max as integer, min as integer dim s as single cls max = 50 min = 100 print "产生的随机数为:" for i = lbound(arr) to ubound(arr) randomize arr(i) = int(rnd * 51) + 50 if arr(i) >

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

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