Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Slim/Player/Playlist.pm
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,9 @@ sub stopAndClear {
}

sub fischer_yates_shuffle {

srand(time()); # make it really random
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a call to srand() in slimserver.pl. Could you please compare results if you added the seed there instead of repeatedly calling srand() here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any results?


my ($listRef) = @_;

if ($#$listRef == -1 || $#$listRef == 0) {
Expand Down
4 changes: 3 additions & 1 deletion Slim/Plugin/RandomPlay/Mixer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ sub getRandomYear {
$years = [ Slim::Schema->rs('Track')->search(\%cond, \%attr)->get_column('me.year')->all ];
}

Slim::Player::Playlist::fischer_yates_shuffle($years); # SQLite's RAND function is not very random. This does a better job.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The you could probably get rid of the sorgin in the query to save a few CPU cycles? Years lists usually aren't long, though 😀 .


my $year = shift @$years;

$cache->set('rnd_years_' . $client->id, $years, 'never');
Expand Down Expand Up @@ -324,4 +326,4 @@ sub playRandom {
}
}

1;
1;