mtwm.net
当前位置:首页 >> vB生成随机数组 >>

vB生成随机数组

将以下代码输入即可 Private Sub Form_Click() '窗体Click()事件 Randomize '防止每次生出随机数一样 Print Int(Rnd * 53) + 1 'rnd()生成[0,1)的随机数,int()是取整 End Sub 改text1的font属性,那有改字号的

纯数组用Int(rnd(1)*数值)先定义好行为x之后令x=Int(rnd(1)*数值)就可以了

Randomize Dim m(8, 8) As Integer Dim mx As Integer, mr As Integer, mc As Integer For i = 1 To 8 For j = 1 To 8 m(i, j) = Rnd * 899 + 0.5 + 100 If m(i, j) > mx Then mx = m(i, j) mr = i mc = j End If Next j Next i MsgBox "最大数是" & mx & ",在第" & mr & "行,第" & mc & "列"

晕!你这是要整个程序还是思路啊?我只能给你个思路!第一步:界面!picturebox和三个command 第二步:程序!1,用随机函数生成数组(就是两个随机函数生成数组,赋予某一个变量)哦,这是二维数组的,一维数组只需要一个随机函数就可以了2,将随机生成数组的这一段程序添加到50次的循环过程中3,分别用不同的排序方法排序并输出(排序其实很简单,就是循环过程中嵌套比较就可以了,输出的时候用格式format输出) 第三步:调试!over!

给你个函数.'// 取得随机字符串 Public Function GetRndString(ByVal lngNum AS Long) As String If lngNum <= 0 Then Exit Function Dim i as Long Dim intLength As Integer Const STRINGSOURCE = "0123456789

private sub command1_click()dim a(1 to 10) as integer, i as integer, t as integer, j as integerrandomize print "随机数:";for i = 1 to 10 a(i) = int(90 * rnd + 10) print a(i);next ifor j = 2 to 10 for i = 10 to j step -1 if a(i) 评论0 0 0

VB可使用Randomize 语句和Rnd 函数输出随机数列到数组.1)Rnd 函数,返回一个包含随机数值的 Single.语法:Rnd[(number)] 可选的 number 参数是 Single 或任何有效的数值表达式.2)Randomize 语句,初始化随机数生成器.语法:

Dim a(1 To 10) As IntegerPrivate Sub Command1_Click() For i = 1 To 10 a(i) = Int(Rnd * 100) Print a(i) Next iEnd Sub 随即产生一个[m,n]的正数公式int(rnd*(n-m+1)+m)祝你学习愉快~~

Fix(Rnd * 2)或者Int(Rnd * 2)是随机生成0和1 你是要生成二维数组吗? Private Sub Command1_Click()Dim a(9, 4) As Byte, s As StringClsRandomizeFor i = 0 To 9s = ""For j = 0 To 4a(i, j) = Fix(Rnd * 2)s = s & CStr(a(i, j)) & " "NextPrint sNextEnd Sub

可以用For循环呀,随机数用VB的RND函数产生,具体可参阅帮助文档,然后For每执行一次添加一个数到列表框里去.Private Sub Command1_Click()Dim i As IntegerFor i = 0 To 29List1.AddItem Int((999 - 100 + 1) * Rnd + 100)NextEnd Sub

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