Home >Backend Development >PHP Tutorial >PHP implements simple probability test

PHP implements simple probability test

*文
*文Original
2018-01-02 11:09:291407browse

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 . &#39;<br />&#39;;
echo $b . &#39;<br />&#39;;
echo $c . &#39;<br />&#39;;
?>

Output result:

##19589

29795
50615

The key is mt_rand( 0,100)

Reflect the probability through the number of occurrences of $a $b $c

Related 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn