MSSQL: Select top 10 * from [Table] order by newid ()
Access:
CopyCode The Code is as follows: 'Use Rs. Move
'Random 10 entries are allowed.
N = 10
'First, You need to determine whether the total number of records is less than 10. If the number is less than 10, then how much if n> 10 rs. recordcount then n = Rs. recordcount
Dim rannum
For I = 1 to n
Randomize ()
Rannum = int (Rs. recordcount * RND) + 1' to generate a random number
Rs. Move rannum 'move the cursor to the random number position
Response. Write I & "-" & RS ("title") & "<br/>" 'output content
Rs. Move-rannum
Next
'......
This is the case. Of course, this may lead to repeated records. You can change the sentence that generates a random number and declare a variable to store the generated random number, when a new random is generated, first determine whether it has been generated. If it has been generated, generate it again. This is simple. You can use instr and so on ~~
The idea is like this. Try it on your own. Another way to avoid repeated reading is to generate only one random number and then read the N records next to the random number. Of course, you also need to make a good judgment. the random number must be smaller than the total number of records-the number of records to be read.
Copy code The Code is 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 content
Rs. movenext
Next
'......
We recommend that you write a simple function to generate and Judge random numbers that are not repeated.