2

I was wondering if there might be a fixed pattern/algorithm being followed by various music player for shuffling the playlist. From my guess i could figure it out that these media players uses same algorithm for shuffling. I say so that practically I have experimented the behavior of shuffle function of various players on the same playlist. Thus if this is the case then what is that algorithm?

Again If my guess is wrong and each player uses its own shuffling algorithm then how come i could get the same sequence of songs after shuffling from various players with same playlist

EDIT:

My question is to know whether all music player share a common algorithm for shuffling. if YES, then which algorithm ? if No, then how come I have got the same sequence of songs after shuffling the same playlist from my nokia mobile 5233, 5300, VLC media Player, Windows Media Player, etc.

Brad Patton
  • 10,668

3 Answers3

1

There are a number of different shuffle algorithms with Fisher-Yates being one of the more popular. Even if a player uses that algorithm it's implementation will depend on a number of other factors (coding language, random number support). Unless a player directly copies code from another program it will be different in implementation.

Additionally while most players 'shuffle' a playlist I've seen ones that always randomly pick the next song to play (resulting in the same song played twice in a row).

It's strange that you claim that different players 'shuffle' the same playlist in the same order. Even using the same algorithm (or same player) should result in a random playlist each time it is shuffled.

Brad Patton
  • 10,668
1

From what I have observed on Apple products, while shuffle does have a random element to selecting which item to play next, there also appears to be a ranking of each item based on playing history, user rating (stars), and inclusion in playlists. Higher ranked items are more likely to appear earlier in the shuffle.

1

I did a small media player for a PSP some time ago (I never relased it) and I implemented the shuffle feature like this:

  • You give every song on your music player an unsigned integer id, ranging from 0 to n (being n the number of songs in the player).
  • Generate a random number using the current time (ms) plus the last song id as seed, make it integer and module with n (the number of songs): |random(time+last_id)|%n. So the pseudo-random id would be in the range from 0 to n and it wouldn't repeat if the space between "shuffles" is less than a milisecond because random(time) would yield the same number if the random seed (the time in this case) is also the same number.
  • Keep a list of the m last played songs so the new pseudo-randomly selected song is not repeated at least between m different songs. If the new song is in the list, repeat step 2.

It worked pretty fine for me, using a list of length .9*n I'd never get a repeated song in bewteen at least 90% of the total songs. This of course is anything but efficient with song libraries with many songs. But a PSP could only store a few hundreds so it was ok.

arielnmz
  • 3,424