How do I get random swapping in arrays?
Sep 26, 2014 at 9:13pm
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!
Sep 26, 2014 at 9:17pm
Last edited on Sep 26, 2014 at 9:18pm
Topic archived. No new replies allowed.