方法名稱:next();功能描述:返回一個0~2147483647之間的整數(shù)
創(chuàng)新互聯(lián)建站堅持“要么做到,要么別承諾”的工作理念,服務領域包括:做網(wǎng)站、成都網(wǎng)站建設、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務,滿足客戶于互聯(lián)網(wǎng)時代的上林網(wǎng)站設計、移動媒體設計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡建設合作伙伴!
方法名稱:next(i);功能描述:返回一個0~i之間的整數(shù)
方法名稱:next(i,j);功能描述:返回一個i~j之間的整數(shù)
方法名稱:Nextdouble();功能描述:返回一個0~1之間的隨機小數(shù)
================
使用方法:
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
==========================
產(chǎn)生N個不同數(shù)的話,我給你個我寫的VB的代碼,你稍微改下:
產(chǎn)生0-10的數(shù):
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
Private Sub Command1_Click()
Dim a(1 To 100) As Integer
Dim i As Integer, j As Integer, k As Integer
For i = 1 To 100 '給數(shù)組a一百個元素賦值,并換每行十個數(shù)字輸出來窗體上
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 '用冒泡排序法對數(shù)組進行排序
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 '輸出排好序的數(shù)組
k = k + 1
Print Tab((k - 1) * 5); a(i);
If k = 10 Then k = 0: Print
Next i
End Sub
'項目:VB中產(chǎn)生在一定正整數(shù)范圍內的不重復的隨機數(shù)'作者:qq15495835Private Sub Command1_Click() Max = 100 '隨機數(shù)上限值 Min = 1 '隨機數(shù)下限值 Amount = 10 '產(chǎn)生號碼數(shù)量(數(shù)量值應小于隨機數(shù)上限值-隨機數(shù)下限值)否則會產(chǎn)生死循環(huán) ReDim a(Amount) Randomize For i = 0 To Amount a(i) = Int((Max - Min + 1) * Rnd + Min) For j = 0 To i If i j And a(i) = a(j) Then i = i - 1 Next Next Text1 = Join(a, vbCrLf)End Sub'請采納參考!謝謝!
Private Sub Command1_Click()
Dim num(6) As Integer
Dim i As Integer, j As Integer
Dim tmp As Integer
Randomize '防止每次生出隨機數(shù)一樣
For i = 0 To 5
num(i) = Int(Rnd * 53) + 1
Next
PrintNum "新生成的6個隨機數(shù)為:", 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個隨機數(shù)為:", num()
End Sub