ASP generation random number ASP generation non-repetitive random number _ Application techniques

Source: Internet
Author: User

ASP generated random number:

Copy Code code as follows:

Randomize ' pure random, not repetitive
Response.Write Int ((999999999 * Rnd) + 111111111) ' generates random numbers from 111111111 to 999999999

ASP does not repeat random numbers:

Method One: Measured

Use the time to notice the character of the split string inside.

Copy Code code as follows:

<%
' generates an array that is not duplicated.
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 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
Exit For ' This sentence is important to prevent unnecessary 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) ' Start number, end number, generate number of
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.