下面是你需要的,經(jīng)過三次隨機,可以看一下,直接調(diào)用函數(shù)返回一個字符就是你要的,看不懂再追問哈
定南網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián),定南網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為定南近千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站建設(shè)要多少錢,請找那個售后服務(wù)好的定南做網(wǎng)站的公司定做!
Structure?jiqi
Dim?num?As?Integer
Dim?num2?As?Integer
End?Structure
Public?Function?chansheng()?As?String
Dim?str?As?String?=?""
Dim?n?As?Integer?=?0
Dim?p68?As?Integer
Randomize()
p68?=?Int(Rnd()?*?2)?+?1
Dim?a(10),?b(8)?As?Integer
For?i?=?1?To?6
b(i)?=?i?-?1
Next
b(7)?=?7
b(8)?=?9
For?i?=?1?To?6
Randomize()
a(i)?=?b(Int(Rnd()?*?8)?+?1)
Next
If?p68?=?1?Then
For?i?=?7?To?10
a(i)?=?6
Next
ElseIf?p68?=?2?Then
For?i?=?7?To?10
a(i)?=?8
Next
End?If
Dim?c(10)?As?Integer
Dim?temp?As?jiqi
Dim?pi(10)?As?jiqi
For?i?=?1?To?10
pi(i).num?=?a(i)
pi(i).num2?=?Int(Rnd()?*?1000)?+?10
Next
For?i?=?1?To?10
For?j?=?1?To?10?-?i
If?pi(j).num2??pi(j?+?1).num2?Then
temp?=?pi(j?+?1)
pi(j?+?1)?=?pi(j)
pi(j)?=?temp
End?If
Next?j
Next?i
For?i?=?1?To?10
str?=?str??pi(i).num
Next
Return?str
End?Function
方法名稱:next();功能描述:返回一個0~2147483647之間的整數(shù)
方法名稱: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
用法 RndString(xx) xx為隨機數(shù)字長度
比如12位長度的隨機字符串 則為 RndString(12)
字符串包含數(shù)字和大小寫字母,函數(shù)如下:
Function RndString(ByVal l As Integer) As String
Randomize()
Dim R, i As Integer
Dim S As Char
Dim returnStr As String
returnStr = ""
'a-z 的ASCII碼是:97-122
'A-Z 的ASCII碼是:65-90
'0-9 的ASCII碼是:48-57
For i = 1 To l
R = Int(Rnd() * 62) '隨機生成的字符有大小寫字母和數(shù)字,共有26個
If R 10 Then '如果小于10,則是數(shù)字 數(shù)字的ASCII是48-57 對應(yīng) 隨機數(shù)字 0-9 所以要將隨機數(shù)字加48
S = Chr(R + 48) 'Chr 是將把數(shù)字按Ascii碼轉(zhuǎn)換為對應(yīng)的字符
ElseIf R 36 Then '如果小于36,則是大寫字母 大寫字母的ASCII是65-90 對應(yīng) 隨機數(shù)字10-35 所以要將隨機數(shù)字加55
S = Chr(R + 55)
Else '如果大于36,則是小寫字母 小寫字母的ASCII是97-122 對應(yīng) 隨機數(shù)字36-62 所以要將隨機數(shù)字加61
S = Chr(R + 61)
End If
returnStr = returnStr + S
Next
RndString = returnStr
End Function