How about this?
1. generate a random number: randomNumber
2. use a sql sentence like:
SELECT * FROM TABLE WHERE ID > randomNumber
(and dont't forget to tell cf to bring only one row: MAXROWS=1)
3. if you don't get any match you try again with a new random number.

I beleive there is a bigger chance this way to get a match a lot faster than
your way.... althought it is not really random, but that depends on how much
randomness you are looking for.

Sorry if it was a stupid idea.

Be happy,
-Andrew McClymont



-----Original Message-----
From: Gary P. McNeel, Jr. [mailto:[EMAIL PROTECTED]]
Subject: 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:
Run a query and get the MAX and MIN IDs.
Do a loop using them as the beginning and ending range and generate a random
number between them.
See if that number exists in the ID field of the db.
If yes, get the record, if not, try again.
Do this until you get a hit.
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.

------------------------------------------------------------------------------
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.

Reply via email to