Jason Salas' WebLog

On-air and online: making people laugh, making people think, pissing people off

Sponsors

ASP.NET sites that kick ass

Pals with blogs

Podcasts I listen to

Cracking the iPod "shuffle" randomizing algorithm

I'm tragically neither a computer science or mathematics major, but I am a software developer (I have a BBA in Marketing and an MBA).  So while I can bang out some heavy code, the major concepts and academic principles so often escape me.  Or are too above my ability to comprehend that I just don't bother paying attention.  That having been said, from a programmatic standpoint, one thing that I've really enjoyed on my iPod Mini is the "shuffle" feature, which not surprisingly plays stored songs or grouped playlists our of their assigned order.  

While not a gimmick that isn't available on tens of thousands of other media-savvy consumer products, the shuffling feature is particularly intriguing because of the way it randomizes digital music.  I've noticed that the shuffle option not only plays my MP3s out of the order in which they're stored, but it also apparently groups random tracks by artist.  For example, if I had 1,000 MP3s stored, 30 of which were by Pantera, when the randomly-ordered playlist got to the first Pantera songs, that song, and the next 29, would all be the Pantera tracks before playing the others.  Interesting little feature, I think.

I've managed to replicate this "grouped randomization" functionality in .NET by playing with a populated DataTable, scrambling the default ordering of the items, and then grouping them by artist (or some other appropriate criterion).  Using the Random class, DataRows are removed from the collection after they've been "played".

But, onto the meat of my argument: does anyone out there more skilled in the academics of math and/or computer science than I know if this is an existing algorithm?  Is there a name for it?

Comments

Mike Hunt said:

yes, i know the algorithm, but you have to be a math major to understand it

# November 28, 2011 5:07 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)