Check some posts for the MSSQL database can generally use such statements:
<%
Select top * from SomeTable ORDER by NewID ()
%>
But if it's an Access database, there's no good workaround.
Method One: Someone uses the following code to first extract the specified number of random numbers as the maximum number of records, and then make the record IDs with these random numbers.
<%
Dim n,j
Dim su ()
Dim a,b,k
b=myrs. RecordCount
Randomize
ReDim SU (Index_n)
SU (1) =int ((b * Rnd) + 1)
For n=2 to Index_n
A=int ((b * Rnd) + 1)
For J=1 to N
Do While A=su (j)
A=int ((b* Rnd) + 1)
J=1
Loop
Next
SU (n) =a
Next
%>
There are some problems with this approach, that is, when the ID is not contiguous, it is possible that some random number does not exist in the ID sequence. The maximum value of the ID is not necessarily equal to the total record value, so some record IDs are always ignored.
Method Two: Someone uses an SQL statement to solve this problem:
<%
Select top * FROM table ORDER by int (rand () *50)
%>
If this statement works, it would be a good idea. I test this statement did not pass, if anyone knows where there is a problem please let me know, thank you very much.
Method Three: There is such a way, I feel good:
<%
Yourstr= "*1*3*4*6*12* ..."
Sql= "SELECT top * Form Yourdb where InStr (' * ' &id& ' * ', '" &yourstr& ') <>0 "
%>
YOURSTR can generate a random number more than the specified number of random numbers as well, which can eliminate the lack of records.
Method Four:
<%
N=10 ' Take any 10 records
Set rs = Server.CreateObject ("Adodb.recordset")
sql = "SELECT * FROM table"
Rs.Open sql,conn,1,1
Count=rs.recordcount ' Total records
If Count<>empty Then
Randomize
For I=1 to n ' Loops n times
Num=fix (rnd*count) ' num is the number of randomly generated rows of records, with fix () so that it is not greater than the count value
Rs.move num ' Move to change random row
Response.Write RS (0) ' out of this record
Rs.movefirst ' Don't forget to move the pointer to the first one.
Next
End If
Rs.close
Set rs=nothing
%>