[mythtv] MythMusic playlists still not intelligent enough IMHO

Lasse Nisted zartzartzart+mythtv-dev at gmail.com
Thu Apr 19 12:42:24 UTC 2007

On 4/19/07, Chris Hamilton <chamilton at cs.dal.ca> wrote:
> > On 4/19/07, Eskil Heyn Olsen <myth at eskil.org> wrote:
> >> On Wed, 2007-04-18 at 10:50 -0400, Dan Wilga wrote:
> >>
> >>> - choose the index of the first song, S, randomly:  S = rand() % N
> >>> - afterward, each new song, S' is calculated like so:  S' = (S + P) % N
> >>>
> The above is a simple Linear Congruential (Pseudo-)Random Number
> Generator, and they are known for being cheap and quick, but with not
> terribly random results.  The higher order bits are fairly random, but
> the lower order bits are not. In fact, for the example you worked
> through above, the numbers will alternate between being odd and even all
> along, showing that the least significant bit has an absurdly small period.
I think a linear congruential pseudo random number generator should involve
a multiplication
(See e.g. http://en.wikipedia.org/wiki/Linear_congruential_generator )
Though, in that wiki A is allowed to be 1. But then, as eskil points
out, it's just
"add P % N".

The problem with more sophisticated RNGs are that some value in
[0..N-1) might be generated twice before having exhausted the entire interval.
(Or am I wrong at that point?)
This was what Dan tried to avoid.

> > I have not followed the discussion, but why not simply create an array
> > [0,1,2,...,N-1] and shuffle this using STL's random_shuffle?
> >
> > A playlist containing 32,000 songs results in a 1MB array, is that
> > really too large?
> >
> > If it is, then the algorithm used in random_sample could be used to
> > select e.g. 1000 unique songs at random. When this list has been
> > played, select 1000 new unique songs (possibly some of those from the
> > first sample, but after 1000 songs one should not care?)
> Explicitly storing an array of indices does seem a little wasteful when
> there are alternative methods of achieving the same results that don't
> require near as much storage space.

I agree, but 1MB of storage ain't much for a _very_ simple solution. I think.

But then again, I would be happy with just the normal RNG selecting
some random song, possibly twice in a row :)

- Lasse Nisted

More information about the mythtv-dev mailing list