I'm going to be processing text files of new customers. Each customer in the file needs to have a random (yet unique) id generated. The requirements state that the id needs to be 6 digits. No word on how many customers I'll get, certainly no more than 999,999 (so I'm told anyway). | [reply] |
Ok, I have to ask. What kind of application are you using
where using pseudo random numbers for customer ids isn't
good enough? I'm already amazed that sequential numbers
can't be used, but not even PRNs?
Well, even if you have 900,001 customers, you have a problem,
unless ids are allowed to have leading 0s. Of course, even
if you have 100,000 customers, using 6 digits for the id
in combination with being truely random and unique doesn't
make much sense.
Abigail
| [reply] |
Why does the ID need to be random? Simply counting the customers would make them all unique.
If it must be random I'd count the customers and change the leading zeros to a generated pseudo random number.
Hope that helps
Chris
Lobster Aliens Are attacking the world!
| [reply] |
I've done something like that.
Instead of using digits, I used 6 (or howevermany) random characters. I used only letters and numbers that didn't look like other characters, so it could be safe from human transcription.
But, after generating the random file name, it's trivial to test if it's a duplicate because the directory itself is a record! You don't have to maintain your own hash. Just see if the candidate file name already exists.
—John
| [reply] |
I'm a little worried that the randomness might be for security reasons. If your objective is to make a valid customer ID number hard to guess, you need to say so now and let the Monks help prevent you from making a terrible mistake.
| [reply] |
Sounds suspiciously like he was trying to figure out lottery numbers to use. :)
| [reply] |