mpv icon indicating copy to clipboard operation
mpv copied to clipboard

playlist-shuffle input command is not random

Open gammoray opened this issue 3 years ago • 0 comments

  • mpv version: mpv 0.34.0-365-g369168b9be
  • Windows Version: Windows 10
  • Source of the mpv binary: https://sourceforge.net/projects/mpv-player-windows/files

Reproduction steps

  1. Create input.conf with a line <some key> loadlist playlist.txt; playlist-shuffle; playlist-next, where playlist.txt is a newline-separated list of audio files. Please note this is specifically related to input.conf. The behavior may be different when shuffle is issued via command line option --shuffle.
  2. Run mpv.exe.
  3. Press the configured key as in input.conf.
  4. Check the order of files in the current playlist.

Expected behavior

The playlist order should not be the same each time the above sequence of steps is performed, with high probability.

Actual behavior

The playlist order is the same each time.

Log file

shuffle_issue.txt

gammoray avatar Jul 10 '22 00:07 gammoray

The playlist-shuffle command calls the C standard library rand() which is a pseudo-random number generator. According to the manpages, rand() will use a seed of 1 unless srand() is called first, which in this case it is not. This gives us deterministic behavior since srand() is not called here.

I agree that this is a bug that should be fixed, since this behavior isn't required for playlist-unshuffle to work. We could always srand() with something non-cryptographic like system wallclock time to make this work.

Traneptora avatar Aug 14 '22 17:08 Traneptora

See if this is fixed after 52e7269ea633b7ac3d83d7b5cba9b15c5fbcbef9

Traneptora avatar Aug 17 '22 14:08 Traneptora

Tested it, it is.

Traneptora avatar Sep 04 '22 12:09 Traneptora