If you want to generate many unique strings, you can easily use a zoned numeric subfield in a data structure and add 1 to the zoned field, giving you strings like A000, A001, up to A999.
But you can generate many more unique strings if you use more characters than just 0 to 9. If you add the alphabetic characters A to Z, in a 3-byte field, you can get 46,656 (36 cubed) different values rather than just 1,000 (10 cubed).
The technique is the same as the way you do addition by hand. Given the sequence of characters '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', say you want to "add one" to the string '01B'. You start with the rightmost "digit" ('B') and add one to it ('C'). This gives '01C'. If you start with 'RPZ', since 'Z' is the last character in your sequence, you can't add 1 to it, so you set it to '0' (the first character in the sequence) and move on to the second character ('P'). Adding one to 'P' gives 'Q', so your result is 'RQ0'.
The following program illustrates the technique.
|
Barbara Morris can be reached by email at
LATEST COMMENTS
MC Press Online