Генерация купонного кода

Я хотел бы генерировать коды купонов, например,AYB4ZZ2, Однако я также хотел бы иметь возможность пометить использованные купоны и ограничить их общее количество, скажем так.N, Наивный подход был бы что-то вроде"generate N unique alphanumeric codes, put them into database and perform a db search on every coupon operation."

Однако, насколько я понимаю, мы также можемattempt to find a function MakeCoupon(n), который преобразует данное число в купоноподобную строку заданной длины.

As far as I understand, MakeCoupon should fullfill the following requirements:

Be bijective. It's inverse MakeNumber(coupon) should be effectively computable.

Output for MakeCoupon(n) should be alphanumeric and should have small and constant length - so that it could be called human readable. E.g. SHA1 digest wouldn't pass this requirement.

Practical uniqueness. Results of MakeCoupon(n) for every natural n <= N should be totally unique or unique in the same terms as, for example, MD5 is unique (with the same extremely small collision probability).

(this one is tricky to define) It shouldn't be obvious how to enumerate all remaining coupons from a single coupon code - let's say MakeCoupon(n) and MakeCoupon(n + 1) should visually differ.

E.g. MakeCoupon(n), which simply outputs n padded with zeroes would fail this requirement, because 000001 and 000002 don't actually differ "visually".

Q:

Does any function or function generator, which fullfills the following requirements, exist? Мои попытки поиска только приводят меня к[CPAN] CouponCode, но оно не полностью удовлетворяет требованию биективности соответствующей функции.

Ответы на вопрос(5)

Ваш ответ на вопрос