生成通过 Luhn 算法的 16 位数字

问题描述

我正在尝试生成通过 Luhn 算法验证的 16 位数字。例如,如果我为一张以 37 开头的美国运通卡生成 16 位数字

像这样

3789 1477 0763 171(这将通过 Luhn 算法)

我能够生成 16 位数字,但它无法通过 Luhn 算法。

<?PHP 

function generatenumber($limit,$prefix){
   $code = '';
   for($i = 0; $i < $limit; $i++) { 
       $code .= mt_rand(0,9); 
   }
   return $prefix.$code;
}

generatenumber(14,37);

3711414458103430  // This wouldn't pass the Luhn algorithm verification)

?>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)