This article mainly introduces the method of generating non-repeating random numbers in ASP. Friends who need it can refer to it.
ASP generates random numbers:
Copy the code code as follows:
Randomize 'Purely random, no repetitions
Response.write Int((999999999 * Rnd) + 111111111) 'Generate a random number between 111111111 and 999999999
ASP does not repeat random numbers:
Method 1: Tested
When using it, you need to pay attention to the characters inside that split the string.
Copy the code code as follows:
<%
'The generated array is a non-repeating array
Function GetRnd(lowerNum,upperNum)
Dim unit,RndNum,Fun_X
unit = upperNum - lowerNum
Redim MyArray(unit)
For Fun_I=0 To unit
myArray(Fun_I)= lowerNum + Fun_I
Next
For Fun_I=0 To round(unit)
RndNum = getRndNumber(Fun_I,unit)
Fun_X = myArray(RndNum)
myArray(RndNum)=myArray(Fun_I)
myArray(Fun_I)=Fun_X
Next
GetRnd = Join(myArray)
End Function
Function getRndNumber(lowerbound,upperbound)
Randomize
getRndNumber=Int((upperbound-lowerbound+1)*Rnd+lowerbound)
End Function
Response.Write GetRnd(1,1000)
%>
Method two:
Copy the code code as follows:
<%
function rndarray(istart,iend,sum)
dim arrayid(),i,j,blnre,temp,iloop,eloop
redim arrayid(sum-1)
i=0
iloop=0
eloop=0
blnre=false
randomize
do while i<sum
temp=int(rnd*(iend-istart+1)+istart)
if i=0 then
arrayid(0)=temp
i=i+1
iloop=iloop+1
else
for j=0 to i-1
if arrayid(j)=temp then
blnre=true
iloop=iloop+1
The sentence "exit for'" is very important to prevent redundant loops.
else
iloop=iloop+1
end if
next
if blnre=false then
arrayid(i)=temp
i=i+1
else
blnre=false
end if
end if
loop
rndarray=join(arrayid)
end function
response.write rndarray(1,5,1) 'Starting number, ending number, how many are generated
%>