I have a UDF that I have used over the years that generates random
strings, etc. that I use throughout applications. In an effort to try
and create a pretty random string I generate an array of alphanumeric
values which I then use as a "seed" array to generate a string of X
characters long.

The core of the function relies on the java.util.collections shuffle
method to randomly re-arrange the array element order. Today I tried
to use the UDF for the first time on OBD and I keep getting strings in
the order I created the seed string. I realized the issue pertained to
the lack of "randomness" in my seed array.

I stripped out my code to a test page to try and find a way to shuffle
the list and I cannot seem to get a random array "back" after invoking
the shuffle method. Here is my test:

<cfscript>
        myArray = [1,2,3,4,5,'A','B','C'];
        al = CreateObject("java", "java.util.ArrayList").init(myArray);
        al2 = CreateObject("java", "java.util.ArrayList").init();
        c = CreateObject('java', 'java.util.Collections');

        al2.add("1");
        al2.add("2");
        al2.add("3");
        al2.add("4");
        al2.add("5");
        al2.add("D");
        al2.add("E");
        al2.add("F");

        c.shuffle(al);
        c.shuffle(al2);
</cfscript>

<cfdump var="#al#" />
<cfdump var="#al2#" />

You will see that both test arrays, "al" and "al2" are in the same
order as when they were created. Any ideas on how to get the
collection's shuffle method to work and OBD to return the resultant?

Any help is greatly appreciated.

Kind regards,
-Jeff Lucido

-- 
Open BlueDragon Public Mailing List
 http://www.openbluedragon.org/   http://twitter.com/OpenBlueDragon
 mailing list - http://groups.google.com/group/openbd?hl=en

 !! save a network - please trim replies before posting !!

Reply via email to