I've got an easier way
- Run a query and populate a list
- Generate a random number from 1 to query.recordcount
- Then use ListGetAt(list, randomnumber) function to get the record
with this code u don't need to have a sequential id field, but the list is
sequential, so u don't have to worry if the number exists of not . :)
[]'s
Vinicius
-----Mensagem original-----
De: Gary McNeel, Jr. <[EMAIL PROTECTED]>
Para: Cf-Talk <[EMAIL PROTECTED]>
Data: Quinta-feira, 15 de Junho de 2000 18:35
Assunto: Easy way to get a random record
>Is there an easy way to pick a random record from a database. I have a
>unique ID for each record, but it is not strictly sequential because of
>record deletions.
>
>Here is my thought:
>
>1. Run a query and get the MAX and MIN IDs.
>2. Do a loop using them as the beginning and ending range and generate a
>random
>number between them.
>3. See if that number exists in the ID field of the db.
>4. If yes, get the record, if not, try again.
>5. Do this until you get a hit.
>6. Alternatively I guess you could gen a random number and take the next
>higher
>number unless it is the highest number.
>
>That seems way to intensive and I know there must be a cleaner way. The
>programmers must know a good way to do this.
>
>Any thoughts or SQL code would be greatly appreciated.
>
>Thanks.
>
>Gary McNeel, Jr.
>Project Manager - DAC-Net, Research & Graduate Studies
>Rice University - Houston
>[W] 713-348-5184
>[M] 713-962-0885
>[H] 713-723-9240
>
>"One good thing about apathy is you don't have to exert yourself to show
>you're sincere about it."
>
>---------------------------------------------------------------------------
---
>Archives: http://www.eGroups.com/list/cf-talk
>To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or
send a message to [EMAIL PROTECTED] with 'unsubscribe' in
the body.
>
------------------------------------------------------------------------------
Archives: http://www.eGroups.com/list/cf-talk
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.