I'm working with arrays on randomness and avoidance of repetition. Excel has helped my debugging with its UNIQUE function (and others like SORT etc). I've attached a screenshot.
Fairly simple to code. While picking Element N, scan through Elements 0 - (N-1). If any of them match, your proposed new element is a duplicate. In that case pick another (random) candidate.
Unfortunately it’s not that easy. I do just that when randomly playing any one of the 26 folders. But to randomly play without repetition from the entire range, some 2,500 tracks, the UNO memory capacity is insufficient to hold the arrays. Even if not the case, I suspect performance might be an issue.
I’m exploring other approaches, and functions like those I’ve mentioned would be very useful.
If all you need to know is whether a given track has been played or not, you only need to store one bit of information per track. That's 2600 bits or 325 bytes ... well within the capacity of even an Uno's RAM.
1. Unique function potential.
I’m considering a compromise approach. Briefly, constructing random subsets, say 200 tracks, and processing them as I do with my folders. The function would help.
2. The bit method.
I agree, and it was also the idea suggested in an earlier thread. One downside is that I’ll have to learn how to work with bits, a new topic for me. Also, it’s likely to conflict with my present folder structure. Even after what I anticipate as the hard work of re-designing the program, with all 2,500 tracks carefully mapped to the existing folder content, any subsequent edit to the micro SD’s content would require some re-coding.
I can think of a much less painless way. I'd just scan the SD during the setup() function to determine number of folders and number tracker per each folder. From that you can determine a simple mapping from Folder # / Track # to an integer (and vice versa). After you have that integer, it's a trivial matter to map it to a bit in an array of unsigned integer data types.
learning is not a downside. You are a microcontroller with limited RAM. If you want to store the state of 2500 tracks on an UNO you can't effort 2500 individual bool variables.
Therefore
take the bit approach or
store the information somewhere else - for example on a external FRAM or
use a controller with more RAM or
just store a limited amount of "last played tracks"