This function seems to be working beautifully. Thank you. Dave
-----Original Message----- From: Christian Cantrell [mailto:[EMAIL PROTECTED]] Sent: Saturday, December 21, 2002 9:39 PM To: CF-Talk Subject: Re: Randomization of a cfquery It's not as easy as it seems. Here's a function that I believe will do the trick. I wrote it pretty quickly, so if you are going to use it, test it thoroughly. Just pass in a query object and it will return a new query object with the rows randomized. You can wrap it in a custom tag if you like, but it makes a good function in my opinion. <cfscript> function queryRandomize(toRandomize) { var size = toRandomize.recordcount; var cols = toRandomize.columnList; var colArray = listToArray(cols); var newQuery = queryNew(cols); var i = 0; var j = 0; var randomRow = 0; // // Create an array of integers that is the size of the record set. // We will draw on this array randomly and resize it dynamically. // var numberBank = arrayNew(1); for (i = 1; i neq size + 1; i = i + 1) { numberBank[i] = i; } queryAddRow(newQuery, size); for (i = 1; i neq (size + 1); i = i + 1) { randomRow = randRange(1, arrayLen(numberBank)); for (j = 1; j neq (arrayLen(colArray) + 1); j = j + 1) { querySetCell(newQuery, colArray[j], toRandomize[colArray[j]][i], numberBank[randomRow]); } arrayDeleteAt(numberBank, randomRow); } return newQuery; } </cfscript> On Saturday, December 21, 2002, at 04:25 PM, David Jones wrote: > Does anyone have a custom tag that will take a regular query and > randomize > the results? I don't have to have a custom tag a database solution > would do > as well. Anything would help at this point. This seems like a simply > thing > to do. I am using Oracle for my backend so if anyone knows of a way > to do > it there that would be great too. > > Thanks in advance, > > Dave > > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4 Subscription: http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4 FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Your ad could be here. Monies from ads go to support these lists and provide more resources for the community. http://www.fusionauthority.com/ads.cfm

