Here's an interesting challenge I've come against. Any ideas how to solve it elegantly?
I need to generate a globally unique "coupon code". Here are the specs:
- it must be globally unique
- it must have the appearance of being random, ie not easy to guess and it mustn't just be 0001, 0002, 0003, etc.
- it's a string of case-insensitive letters and numbers, like "G263782" OR "IIW99D8".
- it should be not too short, but not too long either. If it's too long, it's more likely someone is going to typo trying to punch it in.
- they mustn't be sequential. We don't want AAAAA to be followed by AAAAB and AAAAC
As for globally unique... you can assume we won't be generating more than one of these per microsecond so something that uses microtime() would be acceptable.
But to be really unique it would be nice to hit the MySQL database and use the Primary key id of the inserted row (autoincrementing integer).
Best answer will receive an awesome little banner made by me to put on their website saying how awesome you are.