How Does Music Shuffle Works in a Media Player!
Ipod Shuffle. But How Shuffling Works?? |
Shuffle works just like how you shuffle cards game works! When you hit the play button, it simply randomizes your playlist and plays it until the end, after which it does it again.
Now the technical stuff behind all this is, WMP, Media Monkey, or even the hardware iPod shuffle calls some "random()" function to get a random number from 0 to <1. Then it multiplies it by the number of music files that you have and rounds the result down. This random() & equivalent randomise() function are available in many programming languages such as, JAVA, C++ etc etc.
For example, if you have 150 songs, the first song would have an index of 0 and the 150th song would be having an index of 149. [ Since in computer system every thing starts with zero ].
Say that the random number generated by that random() function, while pressing the next song button is 0.473737. If you multiply that by 150 and round it down, you'll get 71.06055, the index of the 71st song, after rounding off 71.06055 to 71. It then does it again, somehow making sure that the song doesn't get chosen again, until it has completed the playing of of 150 songs.