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

vB产生1到100的随机数

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

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

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

private sub form_load()dim ifor i=0 to 19rendomizetext1(i).text=int(rnd*100)+1nextend sub

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

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

For i = 1 To 100 Randomize Print Int(Rnd * 99 + 1); If i Mod 10 = 0 Then Print Next

dim n, m as integer n = inputbox("请输入二维数组的行数") m = inputbox("请输入二维数组的列数") dim a(n, m) as integer for i = 1 to n for j = 1 to m a(i, j) = int(rnd() * 100 + 1) next next

Private Sub Form_Click() Dim a(9) As Integer, max As Integer, min As Integer, arg As Single, i As Integer Randomize For i = 0 To 9 a(i) = Int(Rnd * 100) + 1 arg = arg + a(i) If i = 0 Or a(i) > max Then max = a(i) If i = 0 Or a(i) < min Then min = a(i) Print

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

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