note 88825 added to function.rand
| From: | cndingo at qq dot com | Date: | Tue, 10 Feb 2009 02:21:29 +0000 |
| Subject: | note 88825 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-150434@lists.php.net to get a copy of this message | ||
<?php
function getRand($min,$max) {
$num=mt_rand($min,$max);
return mt_rand($min,$num);
}
function totalStr($haystack, $needle,$i = 0){
while(strpos($haystack,$needle) !== false) {
$haystack = substr($haystack, (strpos($haystack,$needle) + 1));
$i++;
}
return $i;
}
for ($i=0;$i<=1000;$i++){
$str .= getRand(0,9);
}
for ($i=0;$i<=9;$i++){
echo totalStr($str,"$i")."\n";
}
?>
it printed
304
185
146
121
79
59
49
35
14
9
and I changed.
<?php
function getRand($min,$max) {
$num=mt_rand($min,$max);
return mt_rand($min,$num);
}
function totalStr($haystack, $needle,$i = 0){
while(strpos($haystack,$needle) !== false) {
$haystack = substr($haystack, (strpos($haystack,$needle) + 1));
$i++;
}
return $i;
}
for ($i=0;$i<=1000;$i++){
$str .= getRand(10,19); //change 0,9 to 10,19
}
for ($i=0;$i<=9;$i++){
echo totalStr($str,"$i")."\n";
}
?>
and it printed
282
372
135
115
102
66
44
44
16
11
whay??
----
Server IP: 222.73.227.205
Probable Submitter: 222.128.28.129
----
Manual Page -- http://www.php.net/manual/en/function.rand.php
Edit -- https://master.php.net/note/edit/88825
Del: integrated -- https://master.php.net/note/delete/88825/integrated
Del: useless -- https://master.php.net/note/delete/88825/useless
Del: bad code -- https://master.php.net/note/delete/88825/bad+code
Del: spam -- https://master.php.net/note/delete/88825/spam
Del: non-english -- https://master.php.net/note/delete/88825/non-english
Del: in docs -- https://master.php.net/note/delete/88825/in+docs
Del: other reasons-- https://master.php.net/note/delete/88825
Reject -- https://master.php.net/note/reject/88825
Search -- https://master.php.net/manage/user-notes.php