Mssql:select top * to [table] order by NEWID ()
ACCESS:
Copy Code code as follows:
' To use Rs.move.
' If you randomly take 10 strips
n = 10
' first to determine whether the total number of records is less than 10, if less than 10, then how many how much to take if n>10 Rs.recordcount then N=rs.recordcount
Dim rannum
For i = 1 to n
Randomize ()
rannum = Int (rs.recordcount*rnd) +1 ' produces a random number
Rs. Move Rannum ' moves a cursor to a random number position
Response.Write I & "-" & RS ("title") & "<br/>" ' Output
Rs. Move-rannum
Next
'......
That's it, of course, so it's possible to get a duplicate record, then the resulting random number of the sentence can be changed, declaring a variable to hold the random number has been produced, in the generation of new random to determine whether has been produced, if produced by the regeneration is, this is relatively simple, With InStr and so on can be done ~ ~
The idea is this, others try it yourself. One way to do this is to generate only a random number and then read the N records next to the random number. Of course to write a good judgment, the random number is less than the total number of records-to read the number of records.
Copy Code code as follows:
'......
Dim n,rannum
n = 10
Randomize ()
Rannum = Rs.recordcount-n
If Rannum<1 then Rannum=1
rannum = Int (rannum*rnd) +1
Rs. Move Rannum
For I=1 to 10
Response.Write I & "-" & RS ("title") & "<br/>" ' Output
Rs. MoveNext ' Read down next to
Next
'......
It is recommended that you write a simple function to produce and judge a random number that is not repeated.