• Random Records (2000)

    Author
    Topic
    #363215

    How can I select 20 random records from 100 existing records. I tried to create a calculated field that uses the rnd() function to generate a random number. However, it repeats the same number for each record. Thank you, Andy.

    Viewing 1 reply thread
    Author
    Replies
    • #553725

      Try this link to Dev Ashish’s Access Web site
      http://www.mvps.org/access/queries/qry0011.htm
      HTH

    • #554048

      Did you get your question answered? The problem with Rnd() is that you need to pass it a seed value that changes. An autonumber usually works admirably for this purpose.

      • #554071

        I didn’t really understand the answer. I initially created a query which includes a calculated field. I used rnd() and tried to supply a seed using the Now() function. However, it continued to create the same number each time. E.g. RandNumber:Int(Rnd(Now())*20+1). I also tried a Make Table query using a Random AutoNumber but this doesn’t work either. Can anyone suggest why either of these doesn’t work?

        • #554080

          You need an *existing* value that differs between records. So if you had an autonumber field called KeyID in the underlying table, then Rnd([KeyID]) should give you a unique pseudo-random number for each record in the query. The Now() function is going to return the same value to all of the records because they’re run at the same time.

    Viewing 1 reply thread
    Reply To: Random Records (2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: