ArrayIndexOutOfBoundsException
Hey, I'm new to java and I'm working on a simple program to try and run a simulated card game. I'm trying to construct a deck of 52 cards that will be in random order. Cards have been defined and list is an array of 52 cards, in order. For some reason I am getting an error on my randomizer method, even though I've double checked to ensure the indices are valid yet i'm still getting the ArrayIndexOutOfBoundsException thrown at me. Perhaps i've over looked something, here is the code that contains the error.
private Card[] randomizer()
{
int count = 1;
int num;
int index = 1;
boolean located;
Card[] randomDeck = new Card[52];
int nums[] = new int[52];
for (int x = 1; x <= 52; x++)
nums[x - 1] = x;
while (count <= 52)
{
index = 1;
located = false;
num = (int)(Math.random()*52+1);
while (index < 52 || located == false)
{
if (nums[index - 1] == num) //Error: ArrayIndexOutOfBoundsException
{
randomDeck[count - 1] = list[num -1];
nums[index - 1] = 0;
located = true;
count++;
}
else
index++;
}
}
return randomDeck;
}
Thank you for any help