I have an event with 10 spaces available for booking. When a user registers for the event, I need to assign them a random draw number from 1 through 10. I will include this number in the confirmation email they receive after registration.
I know I can generate the number like this:
$num = random_int(1, 10);
But I can't figure out how to ensure that the number assignment is unique. I can't give someone a number that has already been assigned to another registrant. People will not register at the same time, so I somehow need the function to check against all the previously assigned numbers before assigning a random number from the remaining numbers.
If it matters, event registrants will only be logged-in users, so I could assign something to their user meta if needed.
How would you go about this? Thank you!