Shuffle playlist isn't very random
Opened this issue · 5 comments
Shuffling the playlist does not seem to use a very good random implementation. Reproducible sequences of playlist shuffling on subsequent website reloads and shuffling of new playlists is possible. The RNG seed seems to be some bad default. I'd fix it myself but that takes time. cytu.be needs to be reloaded once y'all patch it.
Did this start happening recently? If so, I wonder if there is a bug in 1ec3eab (introduced by #812).
Something doesn't add up here, shuffle uses Math.random(), certainly not a CSPRNG, but shouldn't be trivially predicable either. It's shared across each instance of the application, so I'm not sure why reloading a channel (which doesn't restart the process) would cause reproducible sequences.
Can you provide more information about the "reproducible sequences"? I tested a few times and didn't notice any obvious patterns.
The patterns in shuffle results could be influenced by bias introduced by multiplying Math.random()
(which returns a floating point number in [0, 1)
) by the array length and flooring it, which does not guarantee uniform distribution. This behavior has been the same since shuffle was implemented, but it's possibly more noticeable when shorter playlists are shuffled.
As for the currently playing item retaining its position, that was introduced by #812, although I have now received feedback from a few people who aren't happy with it so perhaps that feature was accepted too hastily. At the least it should be possible to opt out of it.
Absolutely agree that 812 was hasty. Should be a boolean channel option defaulted to on, but I personally would have it off.