note 81379 added to function.rand
| From: | Anonymous at osu1 dot php dot net | Date: | Mon, 25 Feb 2008 20:37:47 +0000 |
| Subject: | note 81379 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136478@lists.php.net to get a copy of this message | ||
Using the script below with rand() instead of mt_rand(),
I was suprised to find many "words" and part of "phrases" in common.
mt_rand() is highly recomanded when you want to build test cases.
$ressbdd = mysql_connect("localhost", "usr", "pass")
or die("Could not connect: " . mysql_error());
for($i=0;$i<100000;$i++){
$xx1=mt_rand(15,80);
$texte = phrase($xx1);
$sql = 'INSERT into phrases.valeurs set valeur = \'' . $texte .
'\'';
mysql_query( $sql , $ressbdd );
}
//=============================================
function phrase($n){
$phrase='';
for($i=0;$i<$n;$i++){
$xx2=mt_rand(2,20);
$phrase.=mot($xx2) . ' ';
}
return(substr($phrase,0,-1).'.'); // phrase ends with a .
}
//=============================================
function mot($n){
if($n<=0) return 'hello';
if($n>=31) return 'world';
$voyelle
=Array('a','e','i','o','u','y');
$consonne=Array(
'b','c','d','f','g','h','j','k','l','m',
'n','p','q','r','s','t','v','w','x','z');
$mot='';
for($i=0;$i<$n;$i++){
if($i%2==0){
$xx3=mt_rand(0,19);
$mot.=$consonne[$xx3];
}else{
$xx4=mt_rand(0,5);
$mot.=$voyelle[$xx4];
}
}
return $mot;
}
----
Server IP: 195.221.21.36
Probable Submitter: 84.97.242.23
----
Manual Page -- http://www.php.net/manual/en/function.rand.php
Edit -- https://master.php.net/note/edit/81379
Del: integrated -- https://master.php.net/note/delete/81379/integrated
Del: useless -- https://master.php.net/note/delete/81379/useless
Del: bad code -- https://master.php.net/note/delete/81379/bad+code
Del: spam -- https://master.php.net/note/delete/81379/spam
Del: non-english -- https://master.php.net/note/delete/81379/non-english
Del: in docs -- https://master.php.net/note/delete/81379/in+docs
Del: other reasons-- https://master.php.net/note/delete/81379
Reject -- https://master.php.net/note/reject/81379
Search -- https://master.php.net/manage/user-notes.php