Central-limit Gaussians

This is probably more of a stereopsis.com post, but given that this is short idea, I thought I'd just put it here.

iTunes plays all my old music with the same priority as new music, so I wanted to talk about a really simple way to make random numbers that favor recent things...because it's easy! (We did this in a few places in Picasa.)

Mathematically, the "central-limit theorem" says that if you add together a bunch uniform-random samples, you get something that looks like a Gaussian, which favors stuff around its middle, while still providing some likelihood that "tail" values will get picked.

So I want iTunes to do this:

if randx() returns uniform-random numbers in the range -1, 1:

gaussian = fabs(randx() + randx() + randx()) / 3;
iTunes.nextshuffle = dateadded[gaussian * numsongs];

3 comments:

  1. You're probably familiar with Box-Muller, but I'll throw in a link nonetheless because it's also pretty cool.

    ReplyDelete
  2. Neat idea. You might want to add a small constant, just so the songs at the very tail end aren't completely ignored! (e.g. if you have 100 songs, in the current scheme the last song (at the 99th percentile) will only be played 0.0001% of the time.)

    ReplyDelete
  3. One more thought that demonstrations a connection between DSP and statistics I haven't seen made.

    The probability density function resulting from the sum of two probability density functions is their convolution. With randx( ) having a uniform pdf, it's analogous to a box filter, and averaging N calls to rand( ) is the mathematical equivalent of convolving N box filters--e.g., approximating a Gaussian blur with multiple box filters.

    ReplyDelete