tizonia / tizonia-openmax-il

Command-line cloud music player for Linux with support for Spotify, Google Play Music, YouTube, SoundCloud, TuneIn, iHeartRadio, Plex servers and Chromecast devices.
https://tizonia.org
GNU Lesser General Public License v3.0
1.69k stars 87 forks source link

Local playback: playlists are shuffled always in the same way #756

Open juanrubio opened 4 years ago

juanrubio commented 4 years ago

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 commented 4 years ago

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

Tribhuvan0 commented 4 years ago

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

efsiatras commented 3 years ago

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

onio-rgb commented 2 years ago

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

CurlyQuokka commented 2 years ago

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?