in reply to Question: Generate unique/random 12-digit keys for 25,000K records, howto??
Simply assign an id-number to a record every 1/100th of a second and you should be fine via this strategy for about 150 years with unlimited flexibility.use Time::HiRes qw(time); my $id_number = time; $id_number =~ s/\.//; $id_number =~ s/(.{12}).*/$1/;
You will find that the answer to your "actual" question, regarding assigning unique ids with the flexibility of unknown inputs via a functional form, and without collision is a resounding no.my $id_length = 12; my $id_char_set = 16; my $min_data_length = 5; my $max_data_length = 50; my $tiny_alphabet_size = 26; # a-z my $small_alphabet = 37; # a-z, 0-9 and \s my $medium_alphabet_size = 97; # generic western keyboards my $big_alphabet_size = 65536; # utf8 my $world_alphabet_size = 100713; # unicode standard 5.1 my $counter = 0; for my $i($tiny_alphabet_size..$world_alphabet_size){ for my $j($min_data_length..$max_data_length){ for my $k($j..$max_data_length){ my $total_size = geometric_series($i,$j,$k); if($total_size < $id_char_set ** $id_length){ printf " %-5s %-5s %-5s %-5s %-30s\n", $counter++,$i,$j,$k,$total_size; } } } } sub geometric_series { my($base,$min,$max) = @_; my $x; for my $i($min..$max){ $x += $base ** $i; } return $x; }
|
|---|