/ Published in: Perl
Generates a random valid norwegian SSN for dates between 1900 and 1999
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
# # random_norwegian_ssn() # # Accepts one parameter, a date string in the format DDMMYY. # sub random_norwegian_ssn { # Extract date, month, year my ($i1, $i2, $i3); my ($c1, $c2); do { # SSNs for dates between 1900-1999 use an entity number between 0-499 # Pad the entity number to 3 numbers # Calculate the two control numbers my $v1 = (3*$d1) + (7*$d2) + (6*$m1) + $m2 + (8*$y1) + (9*$y2) + (4*$i1) + (5*$i2) + (2*$i3); $c1 = ($v1 % 11) == 0 ? 0 : 11-($v1 % 11); my $v2 = (5*$d1) + (4*$d2) + (3*$m1) + (2*$m2) + (7*$y1) + (6*$y2) + (5*$i1) +(4*$i2) + (3*$i3) + (2*$c1); $c2 = ($v2 % 11) == 0 ? 0 : 11-($v2 % 11); } until ($c1 < 10 && $c2 < 10); }