iPod Shuffle Math

I noticed that my iPod Shuffle repeated songs (in its shuffle mode) more often than I would have expected. But I thought about it a bit. Then I thought a bit more. Then … aha, said I: this is the Birthday Paradox. Which is (to quote Wikipedia): "if there are 23 people in a room then there is a chance of more than 50% that at least two of them will have the same birthday." That's a lot better chance than our untutored intuition would tell us. The same is true with the Shuffle: relatively short sequences of randomly-selected songs contain repeats more often than you'd think.

If my iPod held 365 songs, then it's exactly the same math as the Paradox: about 23 randomly-selected songs would have a better-than-even chance of containing a repeat.

But (right now) it's holding 262 songs, totalling about 17.7 hours of music. So it's clear that makes repeats more likely with songs than with birthdays, right? But how much more? I wrote a script, based on the Wikipedia entry, to do the math:


use strict;
use warnings;

print "Enter number of shuffled songs: ";
chomp( my $d = <> );
print "Enter total playtime (in hours): ";
chomp( my $tot_time = <> );
print "Enter cutoff probability: ";
chomp( my $cutoff = <> );
my $prob = 1;
my $n    = 1;
while ( 1.0 - $prob < $cutoff ) {
    $prob *= ( 1.0 - $n++ / $d );
printf "Probability: %0.3f that\n",                    1.0 - $prob;
printf "%d randomly selected songs\n",                 $n;
printf "out of %d will contain at least one repeat\n", $d;
printf "Approx time for %d songs: %0.1f hours\n",      $n, $n / $d * $tot_time;

No comments on the code, please, just a quick and dirty hack. Results: Out of 20 randomly-selected songs out of 262, there are better-than-even odds that a repeat will occur. (This is about 80 minutes worth of music, since each song averages about four minutes.)

Increasing to 35 random songs (about 2.4 hours worth), the probability of a repeat goes over 90%!

Math is fun and surprising.

Last Modified 2024-01-23 2:06 PM EDT

URLs du Jour (9/1/2005)

OK, maybe I feel a little better now.

  • Shawn Macomber covers the visit of Paul Rusesabagina (hero of the movie Hotel Rwanda) to Bedford, NH. My own congresscritter, Jeb Bradley, comes off particularly poorly. Shawn brings his contrarian perspective and insight to the visit, and the result is very much worth reading.
  • I used to admire Ted Frank back in the day when we both hung out on Usenet, whether I agreed or disagreed with him. So go read him on shooting looters:

    I fully acknowledge that shooting looters is an inappropriately disproportionate response if one views looting as mere larceny. But one doesn't shoot looters to protect property, one does so to protect order. Somebody is going to suffer unjustly when society breaks down. I don't understand why Muller thinks it preferable for the law-abiding citizens to be the cost-bearers. History has shown repeatedly that the way to stop an anarchic riot is an early display of substantial force.

    Good point. I have to (belatedly) add PointofLaw to the blogroll.

Last Modified 2012-10-26 9:22 AM EDT

Blogging Light to Intermittent

Not that it matters much, but I've discovered something about my blogging psychology: it doesn't deal well with times like these. I can blog when I'm irked by something, I can blog when I'm amused, and I can blog when my interest is piqued.

But I have a tough time blogging about things that just make me sad; and most of the stuff I'm seeing the last few days is just saddening.

As often happens Jane Galt makes relevant and insightful comments. Wish I could do that. And you've probably seen Instapundit's list of worthy charities.

I'll be back when I snap out of it.

Last Modified 2005-09-01 11:11 AM EDT