Available ASP random functions without repeated numbers, array implementation, and applied to the random display record set

Source: Internet
Author: User

Tested by the webmaster of the walking home, the available ASP random functions without repeated numbers are implemented in arrays and applied to the random display record set.
Purpose:
This function is applicable to the random display of small numbers without duplicates.
This function is applicable to displaying a small number of random non-repeated record sets.
We do not recommend that you use this function to limit the efficiency by more than one thousand.
Shawl. qiu
2006-09-06
Http://blog.csdn.net/btbtd
Main Content: 100 records are randomly displayed for functions and application functions
Linenum Copy codeThe Code is as follows: <%
Dim rs, rNum
Dim temp
Set rs = createObject ("adodb. recordset ")
Rs. open "select top 100 * 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 random functions without repeated numbers, array implementation, By shawl. qiu
'2006-09-06
'Http://blog.csdn.net/btbtd
'''''''''''''''''''''''''''''''''
'Note: the random number exceeds 1000. This function is not recommended.
'''''''''''''''''''''''''''''''''
'Parameter description:
'''''''''''''''''''''''''''''''''
'Lwnum is the lower limit of the number array, for example, 1
'Upnum is the upper limit of the number array, for example, 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 'awl. qiu Code'
Response. write "<p/> use the random number function to display random numbers between 1 and 100. 1: <br/> --------------------- <br/>"
For each temp in fRndNoRpt (1,100)
Response. write temp & "<br/>"
Next
Response. write "<p/> use the random number function to display random numbers between 1 and 100. 2: <br/> --------------------- <br/>"
Temp = join (fRndNoRpt (1,100 ),"-")
Response. write mid (temp, 1, len (temp)-1)
%>
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.