A
A
Alexey Matal2019-11-21 16:45:05
Programming
Alexey Matal, 2019-11-21 16:45:05

How to generate promotional codes?

Good afternoon!
Tell me, plz, how to generate promotional codes? Perhaps there is an established algorithm/service.
Requirements "standard":

  • Uniqueness (quantity is not limited)
  • Difficult to pick up
  • Going out of order/not having an easily identifiable system
  • Average length of a promotional message (it is planned to be placed on physical media, cards, packages, etc.)
  • A set of Latin letters and numbers, human-readable is not required
  • Automated Generation

Thank you!
ps it is clear that it is easy to program yourself; interested in best-practices)

Answer the question

In order to leave comments, you need to log in

5 answer(s)
R
Robur, 2019-11-21
@Robur

1. Generate a completely random string with the desired length/character parameters
2. check if it exists in the database
3. if so, then n 1.
4. save it to the database.
You are welcome!

K
Konstantin Nagibovich, 2019-11-21
@nki

A GUID is perfect for you.

A
Armenian Radio, 2019-11-21
@gbg

pwgen will handle it

T
TheRonCronix, 2019-11-22
@TheRonCronix

  • choose an algorithm/hash with a uniform distribution.
  • choose a range such that the probability of a code match in relation to the number of promo codes issued is small. If you have a federal network, then the promotional code will be longer, if a small store, then shorter. Perhaps you want the promotional code not to be repeated, then the probability of a collision needs to be further reduced, the promotional code will be more authentic.
  • choose a custom random number generator. Use non-standard seed/salt/set up for a while/set up for equipment.

A
AVS85 S, 2020-02-06
@seoresait

Usually a promotional code consists of 3-4 blocks of 4-5 characters.
You can add to the prefix or postfix (at the beginning, at the end), for example, a year.
Perhaps this service will suit you:
https://pswrd.getcode.xyz/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question