Hi, I have build a lottery system where the winner is given a unique gift card code that they can redeem. The problem is that, when two users do the lottery at the same time and they both win, the same code is given to both users.
Here’s my database:
- Probability number (0~100)
- Unique codes list
- Winner list (connected to winner table)
Here’s my workflow:
Generate a random number → if the random number is lower than the probability number, create winner data and add the first item of the unique codes list to it → remove first item from the unique codes list
I assume that when two users are in this workflow at the same time, they pull the same unique code when they win.
Any idea as to how I can ensure that each code is only given out to a single user? Thanks!