# [mythtv] MythMusic playlists still not intelligent enough IMHO

Dan Wilga mythtv-dev2 at dwilga-linux1.amherst.edu
Thu Apr 19 13:21:40 UTC 2007

```At 10:45 PM -0700 4/18/07, Eskil Heyn Olsen wrote:
>After looking at this, it seems that the pseudorandom order is just
>continuously adding P % N to S and wrapping at N. So essentially, let N
>be 50, P be 15485863 (big prime) and S0 be 20.
>
>  S1 = (20 + 15485863) % 50 = 33
>  S2 = (33 + 15485863) % 50 = 46
>  S3 = (46 + 15485863) % 50 = 9
>  S4 = (9 + 15485863) % 50 = 22

Considering these numbers by themselves, they don't seem terribly
random. But if you only have 50 songs (that's what, 4 CDs worth?),
then I'd say this progression is indeed suitable. When you have a
more realistic number (like 500), then you get:

10, 373, 236, 99, 462, 325, 188, 51, 414, 277

which, again, seems like a good distribution to me. Here's a Perl
program to run tests with:

#!/usr/bin/perl

\$s = 10;
\$n = 500;
\$p = 15485863;

foreach( 1..10 ) {
print "\$s, ";
\$s = (\$s+\$p) % \$n;
}

Of course, if this still isn't satisfactorily random, there's no
stopping you from writing in a list of P's from which one value is
randomly chosen each time you start playing. Or, as Chris Hamilton
suggests, you can go with another algorithm that is similarly
efficient.
--
Dan Wilga                                                        "Ook."
```