Follow along with the video below to see how to install our site as a web app on your home screen.
Бележка: This feature may not be available in some browsers.
<?php
function nonRepeat($min,$max,$count) {
//prevent function from hanging
//due to a request of more values than are possible
if($max - $min < $count) {
return false;
}
$nonrepeatarray = array();
for($i = 0; $i < $count; $i++) {
$rand = rand($min,$max);
//ensure value isn't already in the array
//if it is, recalculate the rand until we
//find one that's not in the array
while(in_array($rand,$nonrepeatarray)) {
$rand = rand($min,$max);
}
//add it to the array
$nonrepeatarray[$i] = $rand;
}
return $nonrepeatarray;
}
//give it a test run
$test = nonRepeat(0,20,20);
echo "<pre>";
print_r($test);
echo "</pre>";
?>
$k = array(0,1,2,3,4,5,6,7,8,9);
$r = array_rand($k, 4);
$chislo = $k[$r[0]].$k[$r[1]].$k[$r[2]].$k[$r[3]];
echo $chislo;
$used = array();
$num = "";
while(strlen($num) < 4) {
$current = rand(0, 9);
if(!in_array($current, $used)) {
$num .= $current;
$used[] = $current;
}
}
print $num;