Description
The latest US compliance test looks for all 8 channels to be covered in 16 steps. The LMIC uses random selection without replacement (and without repetition). When I calculate a Markov chain on 8 channels with this kind of probability, I find that the expected ("average") number of tries to get 8 channels is 19 steps. So you can "expect" to fail the test. You can, of course, re-run. Here's the transition probability matrix.
So... we need to instead use a shuffling algorthm, or expect to have to run the test several times to get a pass. The easiest way to do this is to keep a bit matrix that's a copy of the active channel mask, and clear bits as we use them. Choosing at random requires a search; but the alternative is an n-entry array, where n is the total number of channels. Also, by using a bit map, we can easily implement the join-by-randomly-poking in groups-of-eight scheme recommended by the regional spec. For the US, a map takes 80 bit; for one of the Chinese plans, it takes 96 bits. Even if supporting only 8 channels in practice, you'd still have 64 bits, and much less flexibility for the join hunt. If we always start at the bit of the current channel (rather than starting at bit zero of the map), we'll "usually" find a bit without having to search a lot; and we can remember the max and min channels to further accelerate the search (if needed).