Public Function GetRamCode(f_number)
Randomize
Dim f_Randchar,f_Randchararr,f_RandLen,f_Randomizecode,f_iR
f_Randchar="0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"
f_Randchararr=split(f_Randchar,",")
f_RandLen=f_number '定义密码的长度或者是位数
for f_iR=1 to f_RandLen
f_Randomizecode=f_Randomizecode&f_Randchararr(Int((21*Rnd)))
next
GetRamCode = f_Randomizecode
End Function
///*************这个要好一点***************////
<SCRIPT LANGUAGE=vbscript >
'洗牌
Dim N,S,D,P
P=54'牌的数量
Set D = CreateObject("Scripting.Dictionary")
do while D.Count<P
Randomize
N=Int(P * Rnd + 1)
if not D.Exists(cstr(N)) then
D.Add cstr(N),cstr(N)
end if
loop
for each K in D.Keys
S=S & K & " "
next
msgbox replace(trim(S)," ",",")
</SCRIPT>
access
select top 5 * from [table] order by rnd(id)
sql server
select top 5 * from [table] order by newid()
dim A(9),i
for i = 0 to 9
A(I)=GetRnd(i-1)
NEXT
'得到不重复的随机数
Function GetRnd(n)
Dim i, X
Randomize
X = 10 * Rnd()
For i = 0 To n
If X = A(i) Then
X = GetRnd(n)
Exit For
End If
Next
GetRnd = X
End Function
如果只需要整数把 X = 10 * Rnd()改为 X = cint( 10 * Rnd()),但要小心,如果要取的个数10个大于10 ,就会进入死循环,因为程序用了递归