note 116161 added to function.rand
| From: | Milan | Date: | Mon, 17 Nov 2014 13:13:28 +0000 |
| Subject: | note 116161 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200925@lists.php.net to get a copy of this message | ||
My planet Size generator, precise, end excellent
// giant 4 - is about 30% in galaxy
// large 3 - is about 25% in galaxy
// medium 2 - is about 20% in galaxy
// small 1 - is about 15% in galaxy
// tiny 0 - is about 10% in galaxy
$_perc = array(0.1,0.15,0.2,0.25,0.3);
$countPlanets = 0;
for($i=1;$i<=100;$i++){
for($s=4;$s>=0;$s--){
if(!$_Sizes[$s])$_Sizes[$s]=0;
$percent = $_Sizes[$s]/$countPlanets;
if($percent<$_perc[$s]){
$size = $s; break;
}
}
echo $size;
$_Sizes[$size]++;
$countPlanets++;
}
print_r($_Sizes);
/// result is nice
4321432413042341243004324324131423412430043243241314234124300432432413142341243004324324131423412430
Array ( [4] => 30 [3] => 25 [2] => 20 [1] => 15 [0] => 10 )
----
Server IP: 72.52.91.14
Probable Submitter: 185.9.114.50
----
Manual Page -- http://php.net/manual/en/function.rand.php
Edit -- https://master.php.net/note/edit/116161
Del: integrated -- https://master.php.net/note/delete/116161/integrated
Del: useless -- https://master.php.net/note/delete/116161/useless
Del: bad code -- https://master.php.net/note/delete/116161/bad+code
Del: spam -- https://master.php.net/note/delete/116161/spam
Del: non-english -- https://master.php.net/note/delete/116161/non-english
Del: in docs -- https://master.php.net/note/delete/116161/in+docs
Del: other reasons-- https://master.php.net/note/delete/116161
Reject -- https://master.php.net/note/reject/116161
Search -- https://master.php.net/manage/user-notes.php