randomize array of integers

I am trying to shuffle an array of 52 integers using the following method:

``````	public static List<Integer> shuffleArray(Integer[] arr) {

Integer[] randomizedArray = new Integer[]{};

for(Integer i=0; i<arr.size(); i++) {
Double dbl = math.random() * arr.size();
}
return randomizedArray;
}``````

I want to randomize the array so that the integers are out of order and unique.  Right now, the array is randomized, but it is not unique.  I want all the integers to be unique.  I also want to make sure the order of the array is never 0,1,2,3,4,5,6,7...etc...51.

I'm using the Salesforce apex language above, which is a derivative of Java.  I don't have access to the shuffle method and the random object.  I need to accomplish it with the above code structure.

Any help is appreciated.
Thanks.
SOLUTION
Dave Baldwin

THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.

Thanks for responding to my post.  I tried the following:

``````	public static List<Integer> shuffleArray(Integer[] arr) {

Integer[] randomizedArray = new Integer[]{};
Boolean[] chooseArray = new Boolean[]{};

for(Integer i=0; i<arr.size(); i++) {
}

for(Integer i=0; i<arr.size();) {
Double dbl = math.random() * arr.size();
Integer intgr = dbl.intValue();
if(!chooseArray[intgr]) {
chooseArray[intgr] = true;
i++;
}

}
return randomizedArray;
}

static testMethod void testShuffleArray() {
Integer[] originalArray = new Integer[]{};
for(Integer i=0; i<52; i++) {
}

test.startTest();
Integer[] shuffledArray = BlueWolfCodingExample.shuffleArray(originalArray);
test.stopTest();

system.debug('********************* shuffledArray size ' + shuffledArray.size());
for(Integer j=0; j<shuffledArray.size(); j++) {
system.debug('******************* ' + shuffledArray[j]);
system.assertNotEquals(originalArray[j], shuffledArray[j]);
}
}``````

This is does work most of times, but I'm noticing my unit test fails occassionly because an index in the original list can equal an index in the randomized list.

Perhaps there is a better way to test that the new list is randomized?  Suggestions?

In my test, I just want to show that the array has been randomized.

Thanks for the help!  I appreciate it!
Regards.
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.