in reply to Check randomly generated numbers have not been used before
If you need to create a GUID or UUID, there are better ways to go about this if your constraint can be relaxed to your numbers having a very, very low chance of collision (and such modules exist for this purpose.)
If you absolutely must track these numbers persistently or over a long running process, I'd recommend using SQLite to store your numbers. In the simple table that stores your number, simply mark this column as unique. INSERTing them into the table will let SQLite to efficiently check to make sure this field value is unique . Failure to insert due to a DUPLICATE KEY error could be easily caught, and this would allow you to "try again."
Finally, if you must maintain your own "index" of assigned numbers, I'd recommend storing it in a Trie for efficient storage and fast inserts & lookup.
|
|---|