Pulling random record

1. Scott Wilson Guest

## Pulling random record

This is probably pretty simple but I&#039m new to ASP. <BR><BR>What is the best way to get a random record from a table?<BR><BR>Let&#039s say that I have 10 records and I just want to get a random record and bring it up. I understand how to run Randomize but I guess I&#039m having trouble bridging that to actually retrieving the record. For instance, Randomize can give me a number from 1 to 10 but how do I tell it to get me the record from the table.<BR><BR>Also, how can I prevent Randomize from giving a 0?<BR>

2. mj
Senior Member
Join Date
Dec 1969
Posts
848

## RE: Pulling random record

there is an article on the ASPFAQ&#039s site in the database section that describes how to do this

3. Steve Cimino Guest

## RE: Pulling random record

&#062;&#062;What is the best way to get a random record from a table?<BR><BR>I think you&#039ve already answered it.. with randomize<BR><BR>You could check the ASP FAQs... there is an example how to do this, which will explain it much better than I can.<BR><BR>&#062;&#062;Also, how can I prevent Randomize from giving a 0?<BR>Add a 1 to your statement<BR><BR>x = Int(rnd * 9) + 1 &#039 1 - 10

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## RE: Pulling random record

Steve wrote:<BR>&nbsp; &nbsp; x = Int(rnd * 9) + 1 &#039 1 - 10<BR><BR>Ummm...nope, Steve. That will just give 1 to 9.<BR><BR>The integer you multiply RND by specifies the range of values, from zero to 1 less than that number. So<BR><BR>&nbsp; &nbsp; x = Int(rnd * 10)<BR><BR>give 0 to 9 and all you do is<BR><BR>&nbsp; &nbsp; x = Int(rnd * 10) + 1 <BR><BR>to get the right value.<BR><BR><BR>

5. SC
Senior Member
Join Date
Dec 1969
Posts
125

## D'Oh!

Yep, you&#039re right... wasn&#039t thinking.

#### Posting Permissions

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