- function randomchar(tlen)
- dim tmp,i,j
- for j=1 to tlen step 1
- 'i=randomnumber.value(1,3) 'QTP的用法,不适用于vbs
- Randomize
- i=int((3*rnd) +1)
- '1-大写字母,2-数字,3-小写字母
-
- select case i
- Case 1
- Randomize
- tmp=int(26*rnd)
- tmp=tmp+97
- case 2
- Randomize
- tmp=int(10*rnd)
- tmp=tmp+48
- case 3
- Randomize
- tmp=int(26*rnd)
- tmp=tmp+65
- case else
- msgbox("function:randomchar(tlen) is wrong!")
- end select
- randomchar=randomchar&chr(tmp)
- Next
- end Function
-
- Dim fso,myfile,i
- Set fso=CreateObject("scripting.filesystemobject")
- Set myfile=fso.CreateTextFile("C:\Documents and Settings\Administrator\Desktop\123.txt",True,True)
- i=0
- Do
- myfile.WriteLine(randomchar(14))
- i=i+1
- If i>1200 Then Exit Do
- Loop Until i>1000
复制代码 应该说不会产生太多相同随机数的,但是从打印结果中发现好多相同的,而且是有规律的右移,如下是某次产生的随机数,是搜索sn时的部分结果
Line 789: SN5iqT02P06D72
Line 798: y7SN5iqT02P06D
Line 807: mGy7SN5iqT02P0
Line 816: jvmGy7SN5iqT02
Line 825: oZjvmGy7SN5iqT
Line 834: BFoZjvmGy7SN5i
Line 843: PmBFoZjvmGy7SN
Line 853: SN5iqT02P06D72
Line 862: y7SN5iqT02P06D
Line 871: mGy7SN5iqT02P0
Line 880: jvmGy7SN5iqT02
Line 896: qvtG1SSN5pqT02
Line 905: 5ZqvtG1SSN5pqT
Line 914: BF5ZqvtG1SSN5p
Line 923: 6tBF5ZqvtG1SSN |