How to Prevent Duplicate Gift Card Codes in Lottery System?

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!

Hey Masaki,

Will using this Random string generator plugin help: Random String Generator Plugin | Bubble

It uses the API key

Thanks, but I don’t think this would be a solution.

The codes are generated by Amazon, for example, and I save them in by database. I need to give out these codes to the winners, but with the current set up, the same code is given to the two users if they win at the same time.

I hope this clarifies my situation. Thanks!

Is there any way where you’re storing the codes that have been handed out to someone? If yes, you can search these codes and see if there is any overlap.

Bubble tutorials

I will try that. Thanks!