??? 12/14/06 13:50 Modified: 12/14/06 13:53 Read: times |
#129448 - My approach. Responding to: ???'s previous message |
My own function generates the sequence I posted in the original post. It takes one element as an input and returns the next element in the sequence.
unsigned int GenerateNextNumber(unsigned int seed) { "If all zeros are on the LSB end, start over with (number of zeros + 1) and move them to the MSB end." "Else move the zeros around." } (sorry, can't post the actual code here. My employer would mind.) It works by moving the zeros around in a certain pattern, until all zeros are at the LSB end of the number. Then it starts over with one additional zero and all zeros at the MSB end of the number. I've written a test case to verify that it works correctly. I was just wondering if there was a more efficient way of achieving the same goal, apart from using a table (which would be too big for 16-bit numbers). The generated number represents a subset of a set of 17 elements (one is special and always included, the other 16 can be included or left out). |