in reply to Question: Generate unique/random 12-digit keys for 25,000K records, howto??

2-digit unique/random keys against over 25,000K records.

Using rand and digests is wrong for this.

By far the simplest way for any reasonably low number of values, 25k is very low, is to simply generate the N unique numbers, shuffle them and take the next one of the top of the list and assign it.

Guarenteed unique. Completely random association between the number and what it is assigned to. And trivial to code.

use List::Util qw[ shuffle ]; my @randUnique = shuffle map{ sprintf "1%011d", $_ } 1 .. 25e3;; print $randUnique[ $_ ] for 1 .. 10;; ## First 10 100000016682 100000002653 100000013669 100000004625 100000009482 100000002763 100000022284 100000000048 100000015278 100000012155

The arguement can be made that whilst the association between any given number and what it represents is unguessable, that guessing a valid number, regardless of what it represents is trivial. And if that is the major concern, then a small adjustment is needed.

my @randUnique = shuffle map{ sprintf "%07d%05d", 1e7+int( rand 1e6 ), $_ } 1 .. 25e3;; print $randUnique[ $_ ] for 1 .. 10;; 1091497817847 1018472205890 1028707802676 1078720009752 1016540524132 1074148507607 1022293016846 1018341020021 1038845808717 1056634512933

Now, guessing a valid number has a very low probablity (25e3/1e12 ~= 0.000000025), and even if the bad guy does succeed, there's no way for him to know what his guess represents. Just store your 25k (or a million; it takes no time to generate them):

print time(); my @randUnique = shuffle map{ sprintf "%07d%05d", 1e7+int( rand 1e6 ), $_ } 1 .. 1e6; print time();; 1209603392 1209603398 ## 6 seconds for 1e6

unique random numbers somewhere, and take the next one from the top of the pile as you need it.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."