Thanks Andy and Bobby, that's it! :) So much easier doing in the SQL....
Perfect! ---------------------------------------- From: "Andy Matthews" <[EMAIL PROTECTED]> Sent: Monday, December 19, 2005 12:55 PM To: CF-Talk <[email protected]> Subject: RE: Random Numbers mySQL is SELECT some_column FROM some_table LIMIT 3 ORDER BY RAND() -----Original Message----- From: Bobby Hartsfield [mailto:[EMAIL PROTECTED] Sent: Monday, December 19, 2005 11:33 AM To: CF-Talk Subject: RE: Random Numbers What database are you using? In SQL server you can select the top 3 and order by newid() I'm pretty sure you can do that in MySQL too... I'm just not sure if it's actually 'newid()' in MySQL ----- Else, I can think of a couple different ways to do it.... The simplest way I can think of... Get a list of all the IDS from the table So you'd have a list of IDS like "1,2,3,4,5,6,7,8,9" Then loop from 1 to however many records you want while grabbing a random ID from the list each time and removing it from the list to ensure it doesn't get selected again... thisposition))> When its done, #randomids# will hold 3 random ids then you just select * from table where id in (listofids) That's all untested of course and knowing me... there's a typo somwhere... If there are a ton of records and you don't want to grab all the ids everytime... just grab half or something and randomly order them by different columns and/or asc/desc Eg... Select ID from table Orderby #orderby# #orderdirection# ....:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com -----Original Message----- From: Stuart Kidd [mailto:[EMAIL PROTECTED] Sent: Monday, December 19, 2005 11:32 AM To: CF-Talk Subject: Random Numbers Hi guys, I'm trying to write an app which will choose three random numbers for a competition based on how many etnries there are. I'm having problems trying to work out a way not to choose the same number twice, is there a way to do that which will fit into my CFLOOP structure? Or is there a better way to do it? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Find out how CFTicket can increase your company's customer support efficiency by 100% http://www.houseoffusion.com/banners/view.cfm?bannerid=49 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:227283 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

