Randomizing a Recordset

Results 1 to 2 of 2

Thread: Randomizing a Recordset

  1. #1
    Join Date
    Dec 1969

    Default Randomizing a Recordset

    I am writing a database driven online survey and for each user I would like the order that the questions are asked to random. The questions are pulled from a database. The only idea I have is to load the question ids into a session array by using the following code:<BR><BR>Do While NOT rs.EOF<BR> Number = Int((RandomCount * Rnd)+1)<BR> FNSArray(Number) = rs("FNS")<BR> rs.MoveNext<BR>Loop<BR><BR>Where RandomCount is the number of questions, and FNS is the question id. The problem with this method is that numbers are repeated, so I don&#039;t end up with a value for each array subscript. <BR><BR>I end up with something like:<BR><BR>FNSArray(7) = QID1<BR>FNSArray(3) = QID2<BR>FNSArray(15) = QID3<BR>FNSArray(7) = QID4<BR><BR>So of course when I want to loop through to get the randomized order:<BR><BR>For i = 1 to RandomCount<BR> Response.Write FNSArray(i)<BR>Next<BR><BR>I end up with several empty values since the random numbers would repeat in a few instances. Is there a way to ensure that I won&#039;t get the same random number as I loop through the recordset? Or is there a better way altogether?<BR><BR>

  2. #2
    KPW Guest

    Default RE: Randomizing a Recordset

    http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=65<BR><BR>Always check ASPFAQs.com first!<BR><BR>HTH

Posting Permissions

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