Re: Randomization of a cfquery

2002-12-23 Thread Joe Eugene
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=subscribeforumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Get the mailserver that powers this list at http://www.coolfusion.com



Re: Randomization of a cfquery

2002-12-22 Thread Peter Mayer
http://www.cflib.org/udf.cfm?ID=524

Returns a query object with a specified number of random records from the 

passed query. Some code based on QuerySlice() by Kevin Bridges 
([EMAIL PROTECTED]) 

Best regards,

Peter


Orginale Nachricht
Von: David Jones [EMAIL PROTECTED]
Betreff: Randomization of a cfquery
Datum/Zeit: Saturday, 21. December 2002 22:41:08 

 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=subscribeforumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Get the mailserver that powers this list at http://www.coolfusion.com



RE: Randomization of a cfquery

2002-12-22 Thread Joe Eugene
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.

cfscript
aIdx=arrayNew(1);
for(i=1;i lte queryName.recordCount; i=i+1){
aIdx[i]=randRange(1,queryName.recordCount);
}
/cfscript
cfoutput
cfloop index=k from=1 to=#arrayLen(aIdx)#
#aIdx[k]# . #queryName.ColumnName[aIdx[k]]#br
/cfloop
/cfoutput

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.

 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=subscribeforumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
This list and all House of Fusion resources hosted by CFHosting.com. The place for 
dependable ColdFusion Hosting.



Re: Randomization of a cfquery

2002-12-22 Thread Christian Cantrell
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.

 cfscript
 aIdx=arrayNew(1);
 for(i=1;i lte queryName.recordCount; i=i+1){
 aIdx[i]=randRange(1,queryName.recordCount);
 }
 /cfscript
 cfoutput
 cfloop index=k from=1 to=#arrayLen(aIdx)#
 #aIdx[k]# . #queryName.ColumnName[aIdx[k]]#br
 /cfloop
 /cfoutput

 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.

 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=subscribeforumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
This list and all House of Fusion resources hosted by CFHosting.com. The place for 
dependable ColdFusion Hosting.



RE: Randomization of a cfquery

2002-12-22 Thread David Jones
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=subscribeforumid=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



Randomization of a cfquery

2002-12-21 Thread David Jones
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=subscribeforumid=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



RE: Randomization of a cfquery

2002-12-21 Thread Steve Dworman
I guess a simple solution would be to use the rand() function for the range
of 1 - queryname.recordcount.

Run a loop (queryname.recordcount times) and generate the random list of
integers. use your randomized list and match up each value with the
queryname.currentrow variable (cfquery), and voila you should have a record
set in random order.

I don't have any code for this, but it makes sense to me :)  It might be a
resource hog if your record set is huge though.

 
Steven D Dworman
Macromedia Certified Developer

~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribeforumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Get the mailserver that powers this list at http://www.coolfusion.com



RE: Randomization of a cfquery

2002-12-21 Thread Joe Eugene
Dave,
If i understand.. your question right... this is quite simple.

cfset i=randRange(1,queryName.recordCount)

cfoutput
#queryName.FieldName[i]#
/cfoutput

The above will give you random records...one at a time. if you want all
the records to be random each time.. you might want to put indexes in an
array.. and re-arrange them and just use array notation([]) to pull the
record.


Joe

 -Original Message-
 From: David Jones [mailto:[EMAIL PROTECTED]]
 Sent: Saturday, December 21, 2002 4:25 PM
 To: CF-Talk
 Subject: Randomization of a cfquery


 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=subscribeforumid=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



Re: Randomization of a cfquery

2002-12-21 Thread Christian Cantrell
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=subscribeforumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Get the mailserver that powers this list at http://www.coolfusion.com