Results 1 to 7 of 7

Thread: Need help Randomizing ?? Please take a look

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2000
    Posts
    63

    Question Need help Randomizing ?? Please take a look

    I am trying to create a sql select statement that pulls out records in a random order and then I would like to display them in that random order.

    Any suggestion on the select statement and the actuall code to display would be vastly apreciated.

    Kind Regards,
    Hakan

  2. #2
    Lively Member
    Join Date
    Jan 2001
    Posts
    118
    What I would do is..

    Get your recordset. Get the count of the recordset.

    Use can use rnd function in ASP.

    not actuall code but give you an idea

    do while not rs.eof

    x = rnd(1 * 10) + 1

    if x < 5 then
    response.write rs("Field")
    end if

    rs.movenext
    loop

    just check for the RND function, It is in the MSDN.

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2000
    Posts
    63
    Thank you for your reply, I haven't tried it yet but one quick question what is the "if x < 5" for.

    Thank You
    Hakan

  4. #4
    Lively Member
    Join Date
    Jan 2001
    Posts
    118
    the if x < 5 is for every random number smaller than 5.

    but a more effective way is:

    Declaring a ADODB.Recordset

    Use the RND function to get a random number

    Use the Rs.Move to go to the Random number.

    Just use a check for the number of records returned.

    If will post a example..

  5. #5
    Lively Member
    Join Date
    Jan 2001
    Posts
    118
    http://www.4guysfromrolla.com/webtech/081100-1.shtml

    Will show you how to use a stored proc to generate random record.

  6. #6
    Lively Member
    Join Date
    Jan 2001
    Posts
    118
    this is the way I describe in doing it... but more in detail. (The way you wanted it)

    http://www.4guysfromrolla.com/webtech/072799-1.shtml

    Sorry for not posting the code, but I'm busy. It easier to point you to a correct link

  7. #7

    Thread Starter
    Member
    Join Date
    Jan 2000
    Posts
    63
    I have gotten past that, thank you for your post. If you want to see my new problem go here

    http://161.58.186.97/showthread.php?s=&threadid=82615

    Thanks for your help bud,

    Kind Regards,
    Hakan Azaklioglu

Posting Permissions

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



Click Here to Expand Forum to Full Width