=== Plugins/RandomPlay/Plugin.pm ================================================================== --- Plugins/RandomPlay/Plugin.pm (revision 18987) +++ Plugins/RandomPlay/Plugin.pm (local) @@ -126,27 +126,24 @@ } } - # Search the database for the number of track we need. Use MySQL's - # RAND() function to get back a random list. Restrict by the genre's we've selected. - my @results = (); - my $rs = Slim::Schema->rs($type)->search($find, { + # Search the database for the number of track we need. + # Restrict by the genre's we've selected. + my $rs = Slim::Schema->rs($type)->search($find, { 'join' => \@joins }); - 'order_by' => \'RAND()', - 'join' => \@joins, - }); + my @idList = $rs->distinct->get_column('me.id')->all; + Slim::Player::Playlist::fischer_yates_shuffle(\@idList); + if ($limit) { - @results = $rs->slice(0, ($limit-1)); - - } else { - - @results = $rs->all; + @idList = @idList[0..$limit]; } - $log->info(sprintf("Find returned %i items", scalar @results)); + $log->info(sprintf("Find returned %i items", scalar @idList)); # Pull the first track off to add / play it if needed. + my @results = Slim::Schema->rs($type)->search({ 'id' => { 'in' => \@idList } })->all; + my $obj = shift @results; if (!$obj || !ref($obj)) {