private static function generateRandomSwedishOrganisationNumber($sep) { $new_str = ""; $rand = 0; $seplen = strlen($sep); $cnt = 10 + $seplen; for ($i = 0; $i < $cnt; $i++) { switch ($i) { case 0: $rand = mt_rand(0, 99); $new_str .= sprintf("%02d", $rand); break; case 2: $rand = mt_rand(20, 99); $new_str .= sprintf("%02d", $rand); break; case 4: $rand = mt_rand(0, 99); $new_str .= sprintf("%02d", $rand); break; case 6: if ($seplen > 0) { $new_str .= $sep; } else { $rand = mt_rand(0, 999); $new_str .= sprintf("%03d", $rand); } break; case 6 + $seplen: if ($seplen > 0) { $rand = mt_rand(0, 999); $new_str .= sprintf("%03d", $rand); } break; case 9 + $seplen: // Same calculation as for personal numbers // TODO: move to Utils?? $ctrl = DataType_PersonalNumber::recalcCtrl($new_str . "0", $sep); $new_str .= sprintf("%01d", $ctrl); break; default: break; } } return $new_str; }
private static function generateRandomSwedishOrganisationNumber($sep) { $new_str = ""; $rand = 0; $cnt = 11; // 10 siffers + 1 increment for separator for ($i = 0; $i < $cnt; $i++) { switch ($i) { case 0: $rand = mt_rand(0, 99); $new_str .= sprintf("%02d", $rand); break; case 2: $rand = mt_rand(20, 99); $new_str .= sprintf("%02d", $rand); break; case 4: $rand = mt_rand(0, 99); $new_str .= sprintf("%02d", $rand); break; case 6: $new_str .= $sep; break; case 7: $rand = mt_rand(0, 999); $new_str .= sprintf("%03d", $rand); break; case 10: // Same calculation as for personal numbers // TODO: move to Utils?? $ctrl = DataType_PersonalNumber::recalcCtrl($new_str . "0", $sep); $new_str .= sprintf("%01d", $ctrl); break; default: break; } } return $new_str; }