Scenario:
Imagine a situation where you wish to share a unique alphanumeric code. Perhaps it is a one-time-use coupon code you hand write on business cards, or some other scenario where it is desirable to have a code where mis-keying the entry is unlikely to produce valid result and the another valid code is not readily guessed.
However, when you are issuing these codes you do not have access to the list of codes that have already been issued. Rather, you know only how many have been issued before.
Challenge:
Write a function that generates a unique string of length n, subject to the following constraints:
- Available Characters: Each character in resultant string shall be from a configurable list of allowed values, which may be "hard-coded" into the algorithm.
- Sample List: A, B, C, D, E, F, G, H, J, K, L, M, N, P, Q, R, S, T, U, V, W, X, Z, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 (A-Z and 0-9, omitting "I" and "J")
- Configurable Length Output: The length n of the generated string shall be configurable within the algorithm, for n<=8.
- Input: A seed is available (unique sequential positive integer >=1 and up to 10 digits)
- Stateless: The algorithm has no memory of previously generated strings (no database calls)
- Repeatable: The same seed shall yield the same result
- Unordered Output: Sequential seed values shall not generate strings in any obvious order (that is to say, results should superficially "appear" random)
- For example,
1:"AAAA", 2:"AAAB", 3:"AAAC", ...
would NOT qualify, while1:"RR8L", 2:"1D9R", 3:"TXP3", ...
is on the right track. - Note: While this criterion is admittedly subjective, "degree of randomness" is not intended to be the core aspect of this function. Given the Popularity Contest format, I'll leave it up to the community to decide whether a pattern is too obvious.
- For example,
- Unique Output: String shall be unique, at least within limitations of available characters and requested string length. Therefore, each possible permutation is to be used exactly once before any combination may be reused.
- For example, if configured to generate a string of length n=5 and the available characters include A-Z and 0-9 except for "O", "I" (34 possible characters), then the string may not repeat between seed>=1 and seed<=45,435,424.
- However, if length n=4 with 34 available characters, then the same string need only be unique on seed>=1 and seed<=1,336,336
Winning Criteria:
Popularity Contest - Submission with the most upvotes will be selected as the winner no sooner than two weeks after the first valid solution. Please upvote any and all submissions you feel adequately meet the above criteria.