These are the issues.. with the code below.. 1. Nested loops.. (Overhead) 2. Creating new queries (Overhead). Basically u are making a copy of the resultset. Why cant you work with the original Resultset? 3. UDF's are generally slow... but to manage code.. yes.. it works.
All you need here.. is generate series of random INDEX keys based on given Index Keys. The code can be put in a Java Object/UDF/Custom tags../Include.. whatever.. Thats a personal preference, i would rather use a Java Object..Pass an array of index keys back... Once the algorithm scales...then making it Re-Usable is NOT a big deal. Joe On Sun, 22 Dec 2002 19:43:48 -0500 Christian Cantrell <[EMAIL PROTECTED]> wrote: > The code that I wrote exists inside of a > function, which makes it > modular and reusable. By randomizing the query > results as you display > them, you would have to copy and paste that > code everywhere you wanted > to display query results in a random order > rather than being able to > call one function from several different > places. I create a new query > object because my function is not concerned > with the display of the > results -- it leaves the presentation in the > hands of the caller which > keeps it generic and reusable. > > Christian > > On Sunday, December 22, 2002, at 02:32 PM, Joe > Eugene wrote: > > > I am not sure.. why you are creating a NEW > query... > > This below.. should > work..except..randRange(1,20).. can > > have duplicates..a list value check in the > loop should do it. > > > > > > aIdx=arrayNew(1); > > for(i=1;i lte queryName.recordCount; i=i+1){ > > aIdx[i]=randRange(1,queryName.recordCount); > > } > > > > > > > > #aIdx[k]# . #queryName.ColumnName[aIdx[k]]# > > > > > > Joe > > > >> -----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. > >> > >> > >> 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; > >> } > >> > >> > >> 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 Get the mailserver that powers this list at http://www.coolfusion.com