On Thu, Oct 22, 2026 at 15:34:59 -0000, CGS wrote: > If I select random on a finite song playlist, I wouldn't want the same song > playing twice; this would require an algorithm that would deselect songs that > have already been chosen. Maybe your code accounted for that (or not).
This is covered by keeping track of what's already been selected, either in a second array (which is the more efficient way), or by traversing the playlist to see if the new selection is already in the playlist (the less efficient way). With a very small library, this works well enough. If you have 10 songs, and you generate a playlist by choosing random numbers from 1 to 10 over and over until every number has been selected, it shouldn't take too long. With a large library, however, this is very inefficient. With 10,000 songs, you only have a 1 in 10,000 chance of hitting that final song. You're going to end up looping hundreds of thousands of times, instead of only 10,000 times. If you want a playlist that's as long as your entire library, you should use a shuffling algorithm instead. Load up the array, and then make a single pass through the array, swapping items. The code to do this is in my previous message in this thread.

