3 ms·
One way to do it without retaining additional state would be to generate the initial shuffle for N > current song list. If the new songs' indices come up, they
by AlotOfReading 2y ago
One way to do it without retaining additional state would be to generate the initial shuffle for N > current song list. If the new songs' indices come up, they get played. You skip any indices that don't correspond to a valid song when it's time to play them.
This has some obvious downsides (e.g. an empty slot that was skipped when played and filled by a later insert won't be played), but it handles both insertion and deletions without replaying songs and you only need to store a single integer.