Random retrieve records in a record set Code
<%
'Moving to random record-Steven Jones 'Extension
If not (record set name. bof and record set name. EOF) then
'Reset the cursor to the beginning
If (record set name. cursortype> 0) then
Record set name. movefirst
Else
Record set name. requery
End if
Record set name_totalrn =-1
Record set name_totalrn = record set name. recordcount 'ony works on some recordsets, but much faster
If (record set name _ totalrn =-1) then' and if it didn't work, we still have to count the records.
'Count the total records by iterating through the recordset
Record set name _ totalrn = 0
While (not record set name. EOF)
Record set name_totalrn = record set name_totalrn + 1
Record set name. movenext
Wend
'Reset the cursor to the beginning
If (record set name. cursortype> 0) then
Record set name. movefirst
Else
Record set name. requery
End if
End if
'Now do final adjustments, and move to the random record
Record set name_totalrn = record set name_totalrn-1
If record set name_totalrn> 0 then
Randomize
Record set name. Move int (record set name _ totalrn + 1) * RND)
End if
End if
'All done; You shoshould always check for an empty recordset before displaying data
%>