To shuffle the records in a table, create a query based on that table and
all its necessary fields. Add a calculated field that contains the
Rnd() function with a positive integer variable parameter. Then, sort by this calculated field. Every time that you evaluate the query, the records will be shuffled.
To get <n> records at random, set the query's
TopValues property to the number of records that you want.
The
Rnd() function requires a numeric argument to return a random number. If the argument is greater than zero, the next random number in the
sequence is returned. Because of the way queries are optimized, if you
create a calculated field with a numeric argument such as
the query calculates the
Rnd() function once and then repeats the same value throughout the recordset. To avoid the repetition, create a
calculated field with a variable numeric argument. For example, if the
table has an Employee ID field, you can use the following expression as the
variable numeric argument:
If the table does not have a numeric field, write an expression such as the
following to calculate a numeric value based on any other field:
Expr1:Rnd(Len([First Name]))
The
Rnd() function ignores the expression, but the variable nature of the argument forces the query to evaluate the
Rnd() function for every record.