I'm trying to generate 16 digit number that passes the Luhn algorithm verification. For example, If I'm generating 16 digit number for an American Express card which would begin with 37
Something like this
3789 1477 0763 171 (this would pass the Luhn algorithm)
I able to generate the 16 digit number but it wouldn't pass the Luhn algorithm.
<?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)
?>