sppk.net
当前位置:首页 >> 用VB,生成一个1到100之间的随机数 >>

用VB,生成一个1到100之间的随机数

Dim MyValue Randomize ' 对随机数生成器做初始化的动作。 MyValue = Int((100 * Rnd) + 1) ' 生成 1 到 100 之间的随机数值。

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

Rnd函数产生的是0和1之间的随机数,范围是[0,1),包括0,但不包括1。 因此要产生1~100之间的随机数,可以使用Rnd*98,产生的是[0,98)的随机数,而int(Rnd*98)产生的是[0,97]之间的随机整数,那么int(Rnd*98)+2产生的就是[2,99]之间的随机整数了...

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 Command1_Click() Randomize n1 = 0 n2 = 0 n3 = 0 For i = 1 To 20 x = CInt(Rnd * 100) + 1 j = j Mod 5 + 1 Print Tab(5 * j); x; If i Mod 5 = 0 Then Print If x < 10 Then n1 = n1 + 1 Else If x < 100 Then n2 = n2 + 1 Else...

Dim n As Integer n = InputBox("请输入数组的元素个数") Dim a(n) As Integer For i = 1 To n a(i) = Int(Rnd() * 100 + 1) Next

先把Text1的MultiLine属性设为True,这样文本框才能进行换行 Private Sub Command1_Click() Text1 = "" '清空Text1中的现有文本 Dim score(1 To 20) As Integer, i As Integer, j As Integer For i = 1 To 20 '用随机函数给数组score()赋100以...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Randomize() '产生随机数种子 以防止每次生成结果都一样 Dim a(100) As Integer '声明数组存放数据 用来保存随机数结果 Dim max...

Private Sub Command1_Click() Cls Randomize Dim N As Integer, A As Integer N = 0 For i = 1 To 100 A = Int(Rnd * 90 + 10) Print A; If i Mod 10 = 0 Then Print If A Mod 10 = 1 Then N = N + 1 Next i Print Print "个位数为1的数字的个...

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