随机数字生成器
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
随机数字生成器
Option Explicit
Dim arr() As String
Function CreateRnd(Length As Long) As String
Dim i As Long, r As Integer
For i = 1 To Length
r = Rnd * 9
CreateRnd = CreateRnd & CStr(r)
Next
End Function
Private Sub cmdCancel_Click()
End
End Sub
Private Sub cmdG_Click()
Dim i As Long, c As Long, s As String, out As String, all As Long, l As Long
Randomize
all = CInt(txtC.Text) - 1
l = CInt(txtLen.Text)
ReDim arr(all)
Open txtPath.Text For Output As #1
If chkRepeat.Value = vbChecked Then
Do
s = CreateRnd(l)
For i = 0 To c - 1
If arr(i) = s Then Exit For
Next
If i = c Then
arr(c) = s
c = c + 1
Print #1, s
End If
SetS CStr(c + 1) & "/" & CStr(all + 1)
Loop Until c = all
Else
Do
s = CreateRnd(l)
arr(c) = s
c = c + 1
Print #1, s
SetS CStr(c + 1) & "/" & CStr(all + 1) Loop Until c = all
End If
Close #1
SetS "保存完毕!"
End Sub
Private Sub cmdView_Click()
cd.Filter = "文本文件(*.txt)|*.txt|所有文件|*.*"
cd.ShowSave
txtPath.Text = cd.FileName
End Sub
Sub SetS(s As String)
lblState.Caption = s
DoEvents
End Sub
Private Sub txtPath_Change()
If Len(txtPath.Text) > 0 Then cmdG.Enabled = True End Sub