vb点虐 产生随机数组 vb 随机数
编写一个 VB.NET 程序,产生 100 个 100 以内的随机数,将他们从大到小排序后输出
Private Sub Command1_Click()
创新互联公司主营南城网站建设的网络公司,主营网站建设方案,重庆APP开发公司,南城h5成都小程序开发搭建,南城网站营销推广欢迎南城等地区企业咨询
Dim a(1 To 100) As Integer
Dim i As Integer, j As Integer, k As Integer
For i = 1 To 100 '给数组a一百个元素赋值,并换每行十个数字输出来窗体上
a(i) = Int(Rnd * 101)
k = k + 1
Print Tab((k - 1) * 5); a(i);
If k = 10 Then k = 0: Print
Next i
For i = 100 To 2 Step -1 '用冒泡排序法对数组进行排序
For j = 1 To i - 1
If a(j) a(j + 1) Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next j
Next i
For i = 1 To 100 '输出排好序的数组
k = k + 1
Print Tab((k - 1) * 5); a(i);
If k = 10 Then k = 0: Print
Next i
End Sub
vb点虐 产生随机数
方法名称:next();功能描述:返回一个0~2147483647之间的整数
方法名称:next(i);功能描述:返回一个0~i之间的整数
方法名称:next(i,j);功能描述:返回一个i~j之间的整数
方法名称:Nextdouble();功能描述:返回一个0~1之间的随机小数
================
使用方法:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim rand = New System.Random()
MsgBox(rand.next().ToString())
End Sub
==========================
产生N个不同数的话,我给你个我写的VB的代码,你稍微改下:
产生0-10的数:
Private Sub Command1_Click()
Randomize
Dim a(10) As Long
n = 10
For i = 0 To n
a(i) = Int(Rnd() * (n + 1))
For j = 0 To i - 1
If a(i) = a(j) Then
i = i - 1
Exit For
End If
Next
Next
For i = 0 To n
Print a(i)
Next
End Sub
怎么用vb点虐 随机产生5个不同的数,范围1-33,求帮忙改一下
Private Sub Command1_Click()
Dim num(6) As Integer
Dim i As Integer, j As Integer
Dim tmp As Integer
Randomize '防止每次生出随机数一样
For i = 0 To 5
num(i) = Int(Rnd * 53) + 1
Next
PrintNum "新生成的6个随机数为:", num()
For i = 0 To 5
For j = 0 To 5
If num(j) num(j + 1) Then
tmp = num(j)
num(j) = num(j + 1)
num(j + 1) = tmp
End If
Next
Next
PrintNum "排序后的6个随机数为:", num()
End Sub
当前题目:vb点虐 产生随机数组 vb 随机数
新闻来源:http://hbruida.cn/article/ddgejcs.html