I want to generate an endless series of quasi random numbers to the following specification:-
- Source of numbers is uniformly distributed and random, ranging 0 through 255 inclusive. It's an existing hardware device.
- Required output range is 1 through 8 inclusive.
- Two consecutive output numbers are never the same. For example 5 will never follow 5, but you can have 5,2,5.
- Exactly one output number is required for every single source number. Rejection sampling therefore cannot be used. And while() loops, shuffles etc. can't be used.
It's this last stipulation that's vexing me. The source generator can only supply random bytes at a constant 1 /s and I want output at a constant 1 /s. Typically you'd simply reject a generated number if it was equal to the previous one, and generate another. In my case you only get one shot at each output. I think that it's some sort of random selection process, but this requirement has me going around in circles as I'm a bad programmer. An algorithm, flowchart or picture will do, but I'll be implementing in Java.
Apologies for the semi generic title, but I couldn't really think of anything more accurate yet concise.