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

PHP implements simple probability test

*文
Release: 2023-03-18 21:14:02
Original
1426 people have browsed it

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;;
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template