Results 1 to 6 of 6
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Posts
    989
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Random Records (2000)

    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.

  2. #2
    4 Star Lounger SteveH's Avatar
    Join Date
    Jan 2001
    Location
    Chelsea, Gtr London, United Kingdom
    Posts
    587
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Random Records (2000)

    Try this link to Dev Ashish's Access Web site
    <A target="_blank" HREF=http://www.mvps.org/access/queries/qry0011.htm>http://www.mvps.org/access/queries/qry0011.htm</A>
    HTH
    Steve H
    IT Lecturer/Access Developer
    O2K SR3/O2010; Win7Pro

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Random Records (2000)

    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.
    Charlotte

  4. #4
    5 Star Lounger
    Join Date
    Mar 2001
    Posts
    989
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Random Records (2000)

    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?

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Random Records (2000)

    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.
    Charlotte

  6. #6
    5 Star Lounger
    Join Date
    Mar 2001
    Posts
    989
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Random Records (2000)

    Hey, that's cool!! Cheers Charlotte. (Sorry about the delay in responding).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •