'我不會(huì)計(jì)時(shí),因此下面代碼中沒(méi)有計(jì)時(shí)功能,要你自己去創(chuàng)建。
專注于為中小企業(yè)提供網(wǎng)站制作、成都做網(wǎng)站服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)上栗免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了上1000家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
'Text1 As Label , Sui1 As Button , Sui2 As Button , Sui3 As Button , Fil1 As TextBox , Form1 As Form.
Public Class Form1
Private Sub Sui1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sui1.Click
Dim i As Random = New Random
Dim iText As String = ""
For mn As Int16 = 1 To 30
Dim si As Int16 = i.Next(0, 25)
If si = 0 Then
iText += "a"
ElseIf si = 1 Then
iText += "b"
ElseIf si = 2 Then
iText += "c"
ElseIf si = 3 Then
iText += "d"
ElseIf si = 4 Then
iText += "e"
ElseIf si = 5 Then
iText += "f"
ElseIf si = 6 Then
iText += "g"
ElseIf si = 7 Then
iText += "h"
ElseIf si = 8 Then
iText += "i"
ElseIf si = 9 Then
iText += "j"
ElseIf si = 10 Then
iText += "k"
ElseIf si = 11 Then
iText += "l"
ElseIf si = 12 Then
iText += "m"
ElseIf si = 13 Then
iText += "n"
ElseIf si = 14 Then
iText += "o"
ElseIf si = 15 Then
iText += "p"
ElseIf si = 16 Then
iText += "q"
ElseIf si = 17 Then
iText += "r"
ElseIf si = 18 Then
iText += "s"
ElseIf si = 19 Then
iText += "t"
ElseIf si = 20 Then
iText += "u"
ElseIf si = 21 Then
iText += "v"
ElseIf si = 22 Then
iText += "w"
ElseIf si = 23 Then
iText += "x"
ElseIf si = 24 Then
iText += "y"
ElseIf si = 25 Then
iText += "z"
End If
Next
Text1.Text = iText
Sui1.Enabled = False
Sui2.Enabled = True
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Fil1.Enabled = False
Sui2.Enabled = False
Sui3.Enabled = False
End Sub
Private Sub Sui2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sui2.Click
Fil1.Enabled = True
Sui3.Enabled = True
Fil1.Select()
End Sub
Private Sub Fil1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Fil1.TextChanged
If Fil1.Text.Count = Fil1.MaxLength Then
Fil1.Enabled = False
End If
End Sub
Private Sub Sui3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sui3.Click
Fil1.Enabled = False
Sui2.Enabled = False
Sui1.Enabled = True
Sui3.Enabled = False
'完成結(jié)果。
MsgBox("suidu:" 30)
End Sub
End Class
用法 RndString(xx) xx為隨機(jī)數(shù)字長(zhǎng)度
比如12位長(zhǎng)度的隨機(jī)字符串 則為 RndString(12)
字符串包含數(shù)字和大小寫(xiě)字母,函數(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) '隨機(jī)生成的字符有大小寫(xiě)字母和數(shù)字,共有26個(gè)
If R 10 Then '如果小于10,則是數(shù)字 數(shù)字的ASCII是48-57 對(duì)應(yīng) 隨機(jī)數(shù)字 0-9 所以要將隨機(jī)數(shù)字加48
S = Chr(R + 48) 'Chr 是將把數(shù)字按Ascii碼轉(zhuǎn)換為對(duì)應(yīng)的字符
ElseIf R 36 Then '如果小于36,則是大寫(xiě)字母 大寫(xiě)字母的ASCII是65-90 對(duì)應(yīng) 隨機(jī)數(shù)字10-35 所以要將隨機(jī)數(shù)字加55
S = Chr(R + 55)
Else '如果大于36,則是小寫(xiě)字母 小寫(xiě)字母的ASCII是97-122 對(duì)應(yīng) 隨機(jī)數(shù)字36-62 所以要將隨機(jī)數(shù)字加61
S = Chr(R + 61)
End If
returnStr = returnStr + S
Next
RndString = returnStr
End Function
1.隨機(jī)產(chǎn)生英文字母
Randomize() '功 能:初始化隨機(jī)數(shù)發(fā)生器
Me.txt1.Text = Chr(Asc("a") + Int(Rnd() * 26))
'Rnd 函數(shù)返回小于 1 但大于或等于 0 的值。
'0 = Rnd() * 26 26 是含小數(shù)位的數(shù)
'Int(Rnd() * 26) 轉(zhuǎn)換為整型,就是0~25的隨機(jī)數(shù)
'Asc("a") 得到a的ASCii數(shù)值,是整數(shù)97(A是65)
'a~z的ASCii為97~122 ,即為a~z之間的字母為97加(0~25)
'Asc("a") + Int(Rnd() * 26)為97到122的隨機(jī)數(shù)
'Chr()又可以起到轉(zhuǎn)換成字符的功能,Chr(97)表示a (a轉(zhuǎn)換成數(shù)值又是Asc("a")=97)
'Chr(Asc("a") + Int(Rnd() * 26))就是a~z的隨機(jī)數(shù)了
Randomize() '再次初始化隨機(jī)數(shù)發(fā)生器
Me.txt2.Text = Chr(Asc("A") + Int(Rnd() * 26)) '這里是A~Z的隨機(jī)數(shù)
'也可以換這種寫(xiě)法
Randomize()
Me.txt1.Text = Chr(Int((26 * Rnd()) + 97)) '這里是a~z的隨機(jī)數(shù)
'這是在你知道ASCII碼的情況之下(a~z為97~122,A~Z為65~90)
'Rnd()為0~0.9999999.....的隨機(jī)數(shù)
' 26 * Rnd()為0~25.9999...的隨機(jī)數(shù)
'Int((26 * Rnd())為0~25的隨機(jī)數(shù)
'Int((26 * Rnd()) + 97)為97~122的隨機(jī)數(shù)
'Chr(Int((26 * Rnd()) + 97))就是a~z的隨機(jī)數(shù)了
Randomize()
Me.txt2.Text = Chr(Int((26 * Rnd()) + 65)) '這里是A~Z的隨機(jī)數(shù)
'至于同時(shí)在一處隨機(jī)大寫(xiě)或小寫(xiě),ASCII碼的數(shù)字又不挨在一起(65-90,97-122),比較麻煩。想寫(xiě)的話,你可以自己想一下怎么辦
2.數(shù)字怎樣轉(zhuǎn)換成ASCII碼所對(duì)應(yīng)的字母
Chr()函數(shù)將數(shù)字轉(zhuǎn)換成ASCII對(duì)應(yīng)的字母,Asc()函數(shù)將字母根據(jù)ASCII表轉(zhuǎn)換成數(shù)字
Chr(97)表示a (a轉(zhuǎn)換成數(shù)值又是Asc("a")=97)
3.加到數(shù)組,你可以放在一個(gè)for循環(huán)里
比如
Dim arylst1 As New ArrayList
Dim arr1() As String '數(shù)組
Dim str1 As String
For i As Integer = 1 To 15 '比如我想要15個(gè)隨機(jī)字母
Randomize()
str1 = Chr(Int((26 * Rnd()) + 65)) '這里是A~Z的隨機(jī)數(shù)
arylst1.Add(str1)
Next
ReDim arr1(arylst1.Count - 1) '這里是為了比較動(dòng)態(tài),可以只改變 i 的范圍來(lái)決定要多少個(gè)隨機(jī)字母
'當(dāng)然也可以寫(xiě)死,在前面直接定義為 arr1(14),下次要改的時(shí)候就要改定義的地方和i的范圍,改兩個(gè)地方
arylst1.CopyTo(arr1)
'就把數(shù)值拷貝到數(shù)組里面了
整一個(gè)隨機(jī)數(shù),然后把這個(gè)隨機(jī)數(shù)放進(jìn)textbox里邊就可以了,如果需要隨機(jī)函數(shù)網(wǎng)上很多源碼
你可以換個(gè)思路嘛,隨機(jī)數(shù)只能顯示數(shù)字,但也可以轉(zhuǎn)換為符號(hào)
Dim a
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Randomize()
a = Int(Rnd() * 4) + 1
Select Case a
Case 1
TextBox1.Text = "+"
Case 2
TextBox1.Text = "-"
Case 3
TextBox1.Text = "*"
Case 4
TextBox1.Text = "/"
End Select。
首先說(shuō)一下你不明白的地方,那個(gè)rand.Next(0,
129),其實(shí)就是產(chǎn)生一個(gè)隨機(jī)數(shù)
Dim
rand
=
New
System.Random()
這個(gè)是產(chǎn)生隨機(jī)數(shù)初始化的地方
方法名稱:next(i,j);功能描述:返回一個(gè)i~j之間的整數(shù)
String$(129,
0)的作用和你注釋掉的地方一樣,也是產(chǎn)生一個(gè)0-129之間的隨機(jī)數(shù)
至于為什么報(bào)錯(cuò),問(wèn)題就多了
因?yàn)楫a(chǎn)生的值是一個(gè)隨機(jī)的,而且,程序別的地方的處理我不知道,但只根據(jù)這段代碼來(lái)看,這個(gè)就是個(gè)報(bào)錯(cuò)時(shí)候的顯示信息處理,那么最好你都能明白錯(cuò)誤信息的顯示方法,提示一下,這個(gè)顯示出來(lái)的內(nèi)容,哪怕傳進(jìn)去的參數(shù)一樣,在中文系統(tǒng),日文系統(tǒng),英文系統(tǒng)上顯示出來(lái)的信息內(nèi)容,都是不一樣的
網(wǎng)站名稱:vb.net隨機(jī)字符串 c#隨機(jī)字符串
路徑分享:http://jinyejixie.com/article6/dochjig.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計(jì)、虛擬主機(jī)、網(wǎng)站維護(hù)、品牌網(wǎng)站制作、網(wǎng)站設(shè)計(jì)公司、網(wǎng)站營(yíng)銷
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)