Create random list in ColdFusion (Randomizer)
February 12, 2008 at 7:21 am Taco Fleur Leave a comment
Looking for a way to generate a random list of values in ColdFusion?
The following code generates a random list from myList and puts the random values in myNewList.
<cfscript>
myList = “1,2,3″;
myNewList = “”;
listLength = listLen( myList );
while( listLength neq 0 ) {
myIndex = randRange( 1, listLength );
myItem = listGetAt( myList, myIndex );
myNewList = listAppend( myNewList, myItem );
myList = listDeleteAt( myList, myIndex );
listLength = listLen( myList );
}
</cfscript>
I’ve kept the demo simple and only had 3 items in the list (myList = “1,2,3″) obviously you could use this with a much bigger list.
I have not benchmarked any of this, so I can’t say how it would hold up with a very large list. Any comments to improve are welcome, or if you have bench marked this, let us know
Entry filed under: ColdFusion. Tags: ColdFusion, random list.
Trackback this post | Subscribe to the comments via RSS Feed