MSSQL:selecttop10*from[table]orderbynewid()
ACCESS:
The code copy is as follows:
'To use rs.mov
'If you take 10 random items
n=10
'First we need to determine whether the total number of records is less than 10. If less than 10, how many are there ifn>10rs.recordCountthenn=rs.recordCountCount
dimranNum
fori=1ton
Randomize()
ranNum=int(rs.recordCount*rnd)+1' generates a random number
rs.MoveranNum' Move the cursor to the random number position
response.writei&"-"&rs("title")&"<br/>"'Output content
rs.Move-ranNum
next
'...
This is enough. Of course, it is possible to get duplicate records in this way. Then change the sentence of generating random numbers, declare a variable to store the random numbers that have been generated, and first determine whether it has been generated when generating new randoms. If it has been generated, it will be regenerated. This is relatively simple, you can do it with instr, etc.~
This is the idea, try the others yourself. Another way to not read repeatedly is to generate only one random number and then read N records following the random number. Of course, you must also write a good judgment. The random number should be smaller than the total number of records - the number of records should be read.
The code copy is as follows:
'...
dimn,ranNum
n=10
Randomize()
ranNum=rs.recordCount-n
ifranNum<1thenranNum=1
ranNum=int(ranNum*rnd)+1
rs.MoveranNum
fori=1to10
response.writei&"-"&rs("title")&"<br/>"'Output content
rs.MoveNext' read next to it
next
'...
It is recommended to write a simple function to generate and judge the random numbers without repeating them.