Title
Random passcode
Post
I'm looking to generate a random 4 digit passcode for all our current employees and employees to come and I need to make sure they are all unique. I thought that I could use the auto-enter random calculation and select unique value in validation but I'm worried that this could cause a loop or some sort of strange error in the off chance that the same number comes up twice. Any suggestions to avoid this or is it not a concern?
Define a table with three fields: Passcode, cOrder, Used
Define cOrder as simply:
Random
Use this loop to produce 9999 records in this table:
Loop
Exit Loop if [$K > 9999]
Set Variable [$K ; value: $K + 1]
New Record Request
Set Field [Passcodes::Passcode ; Right ( "000" & $K ; 4 )]
End Loop
Then, if you sort your records by cOrder, you get these values in randomized order to use as your source of passcodes. (This is analogous to shuffling a "deck" of 9999 unique cards and dealing one card to each recipient.)
The example that I have posted is a "proof of concept" example. More sophisticated versions could produce alphanumeric codes.