Random Records

Results 1 to 4 of 4

Thread: Random Records

  1. #1
    Jim D. Guest

    Default Random Records

    I have selected a bunch of data from an Access db using a rather hairy SQL statement. Now, I need to choose 2 of those records randomly. How do I do this?

  2. #2
    Chrace Guest

    Default RE: Random Records

    Rnd(oRS.Recordcount) would do the trick..<BR><BR>Not gonna write it all, but Rnd the amount found and round into an integer. Do it again - if it is the same record (and recordcount &#062; 1) then Rnd again so you get 2 different positions.<BR><BR>Then use a:<BR>i = 0<BR>While not oRS.EOF<BR>i = i + 1<BR>If i = randomvar1 or i = randomvar2 Then<BR>response.write whatever you need<BR>End If<BR>Wend<BR><BR>Semi-pseudo-something-code..but the idea should work. :)<BR><BR>/Chrace

  3. #3
    Join Date
    Dec 1969

    Default RE: Random Records

    Selecting random records is covered by SEVERAL articles on this website (4guysfromrolla.com) as well as the other major ASP sites.<BR><BR>If you have already created a SELECT and want to obtain random recs from THAT resultset, why not retrieve the rows for that SQL statement using GETROWS, and then simply generate 2 random numbers between 0 and the ubound of the GETROWS array, and those would be your two recs?

  4. #4
    Jim D. Guest

    Default RE: Random Records


Posting Permissions

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