Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

closed as unclear what you're asking by MaQleod, kinokijuf, Journeyman Geek May 15 at 10:48

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

3  
The whole point is that if it is supposed to be 'random' then you shouldn't really be able to tell what algorithm is used unless you get the source code or ask the developer. There are open source media players of course. But a quick Google reveals something like this is very commonly used: en.wikipedia.org/wiki/Fisher-Yates_shuffle –  James Mar 20 '13 at 11:57
    
+1 I think you are correct. Its hard to tell exactly which is the algorithm that is being followed. And I too think that the most common algorithm is the Fisher-Yates. Thanks. Just frame it in an answer so that I can accept it. –  Mohsin Akhtar Mar 21 '13 at 5:01
    
even if the algorithms are same, the shuffle result should be random, i mean "you can't get same sequence of songs after shuffuling from various players with same playlist", or there's no need to shuffle cards when playing card games. –  LiuYan 刘研 Mar 21 '13 at 5:19
add comment

3 Answers 3

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.