Modify has hired you to create a program that shuffles playlists[2]. Try your program with your own playlist that has some of your favorite songs. Add the titles of your favorite songs in a text file playlist.txt (one song per line and up to 5000 songs). Write a program that creates a different shuffled playlist of playlist.txt. Create seven different shuffled playlists of playlist.txt (one for each day of the week) and save these playlists in a text file named shuffle[DayOfWeek].txt (one song per line), where [DayOfWeek] is Monday to Sunday.
To solve that problem do the following:
The algorithm looks like that:
To shuffle an array a of n elements (indices 0..n-1):
for i from n-1 downto 1 do
j is a random integer within 0 = j < i
swap(a[j],a[i])
The generated random numbers are really pseudo-random numbers. To create random numbers in C you have to set initially the seed of the random number generator only once (srand(time(0))) and include the appropriate library time.h. The rand() function can be used afterwards as many times as needed and returns a random integer x that is greater than or equal to 0 and less than RAND_MAX. Use the x%k operation to get a number greater or equal to 0 and less than k.