I'm attempting to create an array of random integers that do not repeat. Instead, my array is full of zeroes. We aren't allowed to use things from the outside of our learning such as ArrayList or Arrays class and such. (Pisses me off but I make do).
I haven't tried any other method different as I am still VERY novice, but i've used little iterators and output checkpoints to see what is happening much easier. The random values are initialized but are just not stored.
private Card[] returnShuffled(Card[] cards) {
Card[] shuffled = cards; //Card array
int[] randomIndexes = new int[cards.length]; //Random ?>NONREPEATING integer array.
int randomValue; //Value entered into Random Indexes.
for(int x = 0; x < randomIndexes.length; x++) {
do {
randomValue = (int) (Math.random()*52);
System.out.println(randomValue);
} while(!(search(randomIndexes, randomValue)>-1));
randomIndexes[x] = randomValue; //Point of problem: Printing out the Array after loop gives a list of 0s
}
for(int x = 0; x < shuffled.length; x++) {
shuffled[x] = cards[randomIndexes[x]];
}
return shuffled;
}
private int search(int[] random, int value) {
int token = -1;
for(int i = 0; i < random.length; i++) {
if(random[i]==value) {
token = i;
break;
}
}
return token;
}