Re:“A calculator app? Anyone could make that”
by AlotOfReading on Sunday February 16, 2025 @02:23PM
(#43070822)
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.
Re:“A calculator app? Anyone could make that”
by Dylan16807 on Sunday February 16, 2025 @02:19PM
(#43070795)
> It doesn't. If you add 5 more songs, then the algorithm as presented will just treat it as if you're starting a new shuffle.
You probably shouldn't have quoted "detecting additions and updating the list, etc." then.
It doesn't. If you add 5 more songs, then the algorithm as presented will just treat it as if you're starting a new shuffle.
If you genuinely need to keep track of all the songs you've already played and/or the songs that you have yet to play, then I'm not sure you can do much better than keeping a list of the desired play order, randomized via Fisher-Yates shuffle each time you want a new shuffled ordering -- new songs can be appended to said list and shuffled in with the as-yet-unplayed songs.