This is tougher than I thought it should be. Figured we'd use quotas...and use the quota count. BUT if two respondents complete their forms at (or near) the same time, the quota count will show the same value. Even though the quota decrements properly, the quota count at the time of completion will show the same.
Tried generating a Random Number between 1 and 1000, but that gave us duplicates too (4 times out of ever 20 or so).
Need to get a unique number, between 1 and 1000, without duplicates. We need this to then provide a special username and password for a research study. This way everything is anonymous, but logged against these values.
Looking for a genius idea of how to ensure each respondent gets a unique number from our pool of numbers. Ideas?
Page 1 / 1
One possible flow could be:
- Generate between 1-1000
- Check with previously generated numbers (See here)
- If it's unique, assign to participant and update generated numbers
- If it's not. Got to step 1.
This would be more reliable with random strings of a fixed length.
However, If the numbers being between 1-1000 is not essential, then you could just run
Date.now(), strip a few leading digits and assign that. In the same timezone, two people would need to have the exact same start time at the precision of milliseconds to get the same number, however this could be an issue in different time zones and system clocks. To add some jitter, you could use
performance.now().
Ref
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.