in reply to Re: Music shuffling
in thread Music shuffling

The simplest solution I found to the OP issue was to divide the track list in two halves, then play each one of them alternately:

## pseudocode my @list = shuffle get_tracks; my @list1 = @list[0..@list/2-1]; my @list2 = @list[@list/2..$#list]; while (1) { play @list1; play @list2; shuffle @list1; shuffle @list2; }

Regarding this:

Now, how you gonna make sure that NIN isn't followed by Elton John.

I have thought about a database with style tags and a mechanism for specifying which styles are allowable after a given song:

## pseudocode my @style_levels = ( [ qw/noise/ ], [ qw/metal heavy/ ], [ qw/pop rock/ ], [ qw/chill_out classical/ ], ); sub get_next_song { my $cur_song = shift; my $cur_style = get_style_from_db $cur_song; ## now we have 'pop' +, 'classical'... my $index = get_index $cur_style; ## walk @style_level +s and return the index where 'pop' or 'classical' has been found my $next_index = $index + (-1,0,1)[rand 3]; ## randomly go to ne +xt, current or previous style level (TODO: bounds checking) my $next_style = ${ $style_levels[$next_index] }[ rand @{$style_le +vels[$next_index]} ]; ## choose a style of this level return get_song { style => $next_style }; ## pick some song of + this style }

--
David Serrano