tizonia-openmax-il icon indicating copy to clipboard operation
tizonia-openmax-il copied to clipboard

Local playback: playlists are shuffled always in the same way

Open juanrubio opened this issue 4 years ago • 5 comments

Issue

Description

As reported in Gitter by user @evilblade666

Hi, guys. My home internet is down for a time here, so I'm listening for my local music and I've noticed a thing.. So the command is tizonia /path/to/local/music/folder/ -r -s Well, it plays and shuffles my entire music allright, BUT! it shuffles it the same way EVERY time! :) Only when I modify the contents of a folder by adding/removing something - then the playlist becomes different :) Can I do something to make this shuffled playlist different every time I run the command?

The problem seems to be that the random generator is not seeded before calling std::random_shuffle in:

https://github.com/tizonia/tizonia-openmax-il/blob/ca7e48a392618e5d1dee3e388cc15fad5eaa66c3/player/src/tizplaylist.cpp#L231

Steps to Reproduce

  1. Play any local directory that contains mp3s using tizonia ~/Music --shuffle. Observe the playlist created.
  2. Repeat the above step, and the playlist is always the same

Expected behavior:

Correctly randomized playlists every time.

Reproduces how often:

Always

Versions

Latest (0.22.0)

Installation Method Used

Any

juanrubio avatar Aug 18 '20 08:08 juanrubio

The solution is to seed the random generator before shuffling the list: https://stackoverflow.com/questions/14221763/stdrandom-shuffle-produces-same-result-each-time

juanrubio avatar Aug 18 '20 08:08 juanrubio

Hey, i'm a newbie to open source and i want to work on this issue. Please guide me further

Tribhuvan0 avatar Dec 01 '20 02:12 Tribhuvan0

This issue can be closed, as this is already fixed by #766.

efsiatras avatar Mar 03 '21 13:03 efsiatras

Yeah but the last fix used a srand() in the function itself which is not the most optimal way to regenerate a seed.

onio-rgb avatar Nov 05 '22 00:11 onio-rgb

Yeah but the last fix used a srand() in the function itself which is not the most optimal way to regenerate a seed.

@onio-rgb Could you please elaborate a bit more? Why srand() here is bad and what would be more optimal?

CurlyQuokka avatar Nov 11 '22 09:11 CurlyQuokka