Skip to content

Instantly share code, notes, and snippets.

@synchrone
Created September 18, 2012 12:45
Show Gist options
  • Save synchrone/3742894 to your computer and use it in GitHub Desktop.
Save synchrone/3742894 to your computer and use it in GitHub Desktop.
Генератор ИНН
<?php
function random_number($length=1){
$number = array();
for($i=0; $i < $length; $i++){
$number[] = mt_rand(0,9);
}
return $number;
}
function company_itn(){
$n = random_number(9);
array_unshift($n,0); //for checksum indexes
$n[] = ((2*$n[1] + 4*$n[2] + 10*$n[3] + 3*$n[4] + 5*$n[5] + 9*$n[6] + 4*$n[7] + 6*$n[8] + 8*$n[9]) % 11) % 10;
array_shift($n);
return implode($n);
}
function personal_itn(){
$n = random_number(10);
$n[] = (($n[0]*7+$n[1]*2+$n[2]*4+$n[3]*10+$n[4]*3 +$n[5]*5+$n[6]*9+$n[7]*4+$n[8]*6+$n[9]*8)%11)%10;
$n[] = (($n[0]*3+$n[1]*7+$n[2]*2+$n[3]*4 +$n[4]*10+$n[5]*3+$n[6]*5+$n[7]*9+$n[8]*4+$n[9]*6+$n[10]*8)%11)%10;
return implode($n);
}
$opts = getopt('n:t:');
$caller = $opts['t'].'_itn';
for($i=0; $i < $opts['n']; $i++){
echo $caller().PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment