我想在 120 对中生成 3 位数字 没有重复和重复的数字 示例:012
013、132 有效 011,333、022,202210
无效 注意:冗余数字都出现因此012
无效210
我正在使用 PHP 版本 5.6.28 Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/5.6.28 这是我迄今为止尝试过的,但没有运气。
数计数:120 027 028 029 036 038 046 069 074 079 093 105 106 109 123 143 145 149 152 153 162 167 175 182 195 198 204 208 213 216 217 219 235 243 275 287 294 301 302 310 327 341 342 347 352 357 358 365 369 376 378 380 384 392 402 408 415 423 428 431 453 465 467 468 490 493 496 506 509 510 512 524 537
541 561 573
591 597 598 609 629 631 634 639 647 689 691 694 697 703 719 723 743 745 750 752 759 761 813 819 820 824 829 840 865 875 890 905 907 912 916 917 921 930 941 945 947 963 965 973 984
注意这里537
是573
无效的
/*----Numbers.php----*/
class Numbers{
private $num_set = array();//get 3 digit
private $num_basket = array(); //container
public $codeNum = "0123456789";
public function get_basket(){
return $this->num_basket;
}
public function put_basket($num){
$this->num_basket[] = $num;
}
public function is_exist($num_taken){
if(in_array($num_taken, $this->num_basket)){
return true;
}else{
return false;
}
}
public function generate_num(){
while(count($this->num_set) < 3){
$get_one_digit = $this->getToken(1);
if(!in_array($get_one_digit, $this->num_set)){
$this->num_set[] = $get_one_digit;
}
}
$three_digit = implode($this->num_set);
$this->num_set = array();
return $three_digit;
}
protected function getToken($length)
{
$token = "";
$max = strlen($this->codeNum); // edited
for ($i=0; $i < $length; $i++) {
$token .= $this->codeNum[$this->crypto_rand_secure(0, $max-1)];
}
return $token;
}
}
代码工作正常,不显示错误,但不显示预期结果。我真的需要帮助。我将不胜感激任何帮助。
宝慕林4294392