I have a situation where we print runs of “discount cards”, where a unique code is printed on the card that a user can redeem in an online store for a discount.
We create so many of these cards, and in fact few people use them, so I would like to use a certain form to determine the valid code using the method, and not to store each individual code in the database. We create about 5,000 of these codes at the same time. Probably about 5 times a year.
Ideally, I would like to have something like:
$coupons->generate(5000, 'unique_salt', 'prefix_');
To generate 5,000 "random" codes, such as:
prefix-23-3424-4324-3344 or prefix-4H-34RE-22K3-PE3W
unique salt and prefix_ will be stored in the database. These codes can then be checked with prefix_ to search for salt and determine if the code is valid or not.
I have the look of this work, using a number as a salt, to find numbers dividing by salt, and then reordering the numbers so that they seem random. With sufficiently long codes, some work will be required to define a template. But I would like to think that there is a better way ... because there are only so many numbers that give large numbers of codes that are divided by salt .
(For example, salt 2 will give 5000 codes from 1 to 10000 (and it will be easy to see the picture) ... but salt 14000 will give zero codes from 1 to 10000).
Another advantage of this is that I can generate coupons as needed (for example, when we give individuals a discount on a one-by-one basis) and be able to track which coupons are used, when, etc. based on prefix_ ... and potentially see how / when cards are transmitted, which gives the best result.
Am I just spinning my wheels when I just need to store each code in a database? (Or just fun?) :)