I am trying to write a sub-program that takes a deck of 52 cards and will shuffle it up using this algorithm:
Start with n=51
Repeatedly:
Generate a random integer between 0 and n. Call it i.
Swap card i and card n in the deck.
Decrease n by 1
However the code that I've written,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
vector<int> shuffleDeck(vector<int> deckVector)//deckVector is the original deck in order
{
int temp, n, i, s;
n = 51;
for(n = 51; n >=0 ; n--)
{
// following code should swap out random values for the highest vector place
i = randomize(0);// randomize(0) generates random number between 0 and 51
temp = deckVector[n];
deckVector[n] = i;
deckVector[i] = temp;
}
return deckVector;// this is supposed to be the shuffled deck
}
when I output the new vector, only produces this output(note- it is a random number every time, but it just repeats over and over):