慕容708150
您可以使用此函数生成超过1任何最大值的数字字符串PHP_INT_MAX(最大值和结果都必须是字符串)重要提示:不要将其用于加密,因为并非所有数字都有相同的被选择机会:由于我们默认为零到“1”,结果“1”的机会加倍我们随机选择每个字符,因此根据选择的最大值,并非所有数字都有相同的机会<?phpfunction notCryptoRandomDecimalString($maxStrValue){ $result = ''; $maxBegin = ''; for($i = 0; $i < strlen($maxStrValue); $i++){ $maxDigit = $maxStrValue[$i]; //if beginning of the result is same than beginning of the max, //we limit random to current char from maximum, or else it can be from 0 to 9 if($result === $maxBegin){ $result .= random_int(0, $maxDigit); }else{ $result .= random_int(0, 9); } $maxBegin .= $maxDigit; } //remove leading zeroes $result = ltrim($result, '0'); //if zero was picked, default to 1 if($result === ''){ $result = '1'; } return $result;}echo(notCryptoRandomDecimalString('18446744073709551615'));