This article mainly introduces a simple probability-related code implemented in PHP. It analyzes the principles and usage skills of probability statistics through digital operations. Friends in need can refer to it. I hope to be helpful.
The details are as follows:
<?php for($i=1;$i<100000;$i++){ $x=mt_rand(0,100); if($x<20){ $a=$a+1; } else{ if($x<50){ $b=$b+1; } else{ $c=$c+1; } } } echo $a . '<br />'; echo $b . '<br />'; echo $c . '<br />'; ?>
Output result:
29795
50615
The key is mt_rand( 0,100)
Reflect the probability through the number of occurrences of $a $b $cRelated recommendations:
php Implementation of progress bar sample code
php Implementation of full English name random numbering code
php implements event candidate lottery function code
The above is the detailed content of PHP implements simple probability test. For more information, please follow other related articles on the PHP Chinese website!