I'm trying to generate several 5- and 6-bit random numbers for a project. The challenge is that none of the 6-bit numbers can be the same, while some of the 5-bit values can repeat, but with some restrictions. I initially thought about using a bit manipulation technique that involves rotating and XORing, but I realized that it leads to repeated sequences. For example, my generated 6-bit sequence breaks down into multiple smaller sequences, which is fine since I only need four unique values from them. However, I also need to create three distinct 5-bit values, but I'm worried that the method I came up with could fail if they all return the same number. Are there simpler pseudorandom number algorithms for low-bit counts that avoid short cycles like this?
1 Answer
Instead of trying to come up with a complex algorithm, you might want to check out some shuffle algorithms. They work better with the limited permutations you have. They're simple and can help avoid the issues you're facing with sequences.
That sounds interesting! Do you have any specific shuffle algorithms you like?