How do I get random swapping in arrays?
I'm trying to figure out how to randomly swap different elements in an array of structures, but I'm stuck. Wondering if anyone could help me out.
This is what I have so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
void shuffle()
{
Music temp;
unsigned int currentTime = (unsigned)time(0);
srand(currentTime);
for (int i = 0; i < NUM_SONGS; i++)
{
songs[i] = temp;
i = (rand() % NUM_SONGS) + 1;
temp = songs[i];
}
}
|
Any help is appreciated!
Last edited on
Topic archived. No new replies allowed.