Cloud-dwelling Community webmaster Test available ASP No repetitive digital random function, array implementation, and applied to random display recordset
Role:
This function is suitable for randomly displaying a small number of random repeat numbers
This function is useful for displaying a small number of random, distinct sets of records
In order not to affect efficiency, the upper limit is over 1000, this function is not recommended
Shawl.qiu
2006-09-06
Http://blog.csdn.net/btbtd
Main content: Functions and application functions randomly display 100 records
LineNum
Copy Code code as follows:
<%
Dim rs, Rnum
Dim temp
Set Rs=createobject ("Adodb.recordset")
Rs.Open "SELECT top * from Rnd_v1", conn,1
Rnum=rs.recordcount-1
For each temp in frndnorpt (0,rnum)
Rs.move Temp
Response.Write rs ("Sbcat")
Response.Write "<br/>"
Rs.movefirst
Next
Rs.close
Set rs=nothing ' Shawl.qiu code '
function Frndnorpt (lwnum,upnum)
''''''''''''''''''''''''''''''''''''''''''''
' ASP no repetitive digital random function, array implementation, by Shawl.qiu
' 2006-09-06
' HTTP://BLOG.CSDN.NET/BTBTD
'''''''''''''''''''''''''''''''''
' Note: More than 1000 random numbers are not recommended for use in this function.
'''''''''''''''''''''''''''''''''
' Parameter description:
'''''''''''''''''''''''''''''''''
' Lwnum is the lower limit of the number array, such as: 1
' Upnum is the upper limit of the number array, such as: 100
'''''''''''''''''''''''''''''''''
' Sample call:
'''''''''''''''''''''''''''''''''
' Dim t
' For each T in Frndnorpt (1,100)
' Response.Write t& ' <br/> '
' Next
''''''''''''''''''''''''''''''''''''''''''''
If Upnum<1 or IsNull (upnum) or upnum= "" or IsNumeric (upnum) =false then Exit function
If Lwnum<0 or IsNumeric (lwnum) =false then Exit function
Dim num, Temp
Dim ar ()
ReDim ar (Upnum)
Dim j:j=0
For Temp=lwnum to Upnum
num=num& "." &temp& "."
Next
Randomize
Do Until num= ""
Temp=int ((upnum-lwnum+1) *rnd+lwnum)
If INSTR (num, "." &temp& ".") <>0 Then
Num=replace (num, ".") &temp& ".", "" ")
AR (j) =temp
J=j+1
End If
Loop
Frndnorpt=ar
Erase AR
End Function ' Shawl.qiu code '
Response.Write "<p/> use random number function to display 1 to 100 1:<br/>-----------------------<br/>"
For each temp in frndnorpt (1,100)
Response.Write temp& "<br/>"
Next
Response.Write "<p/> use random number function to display 1 to 100 2:<br/>-----------------------<br/>"
Temp=join (Frndnorpt (1,100), "-")
Response.Write Mid (Temp,1,len (temp)-1)
%>