You are looking at implementing a simple
adder.
For example, given a number, 23, if I add ONE to it I get 24.
Likewise, if I add one to 99 I get 100.
This is because each digit has
eleven possible values: 0..9 and SPACE.
" "
" 0"
" 1"
" 2"
...
" 8"
" 9"
" 1 "
" 10"
|
Easy enough. By simply NOT SHOWING combinations where there are spaces to the right of the leftmost non-space, you can do the amazing!
In fact, you can make your adder never wrap around to space, but to 1 from a space and to 0 from a non-space. Then you get the proper sequence:
" 0"
" 1"
...
" 8"
" 9"
" 10"
" 11"
|
Finally, you stop when you have made it through each digit and still have a carry.
"9998"
"9999"
"0000" (but wants to be "10000", because the one carries)
|
For a random length, it is the same as getting any other random number. Get some N and set s[N] to zero, then start adding at s[N-1] and continue to s[0].
Hope this helps