Home >Backend Development >PHP Tutorial >How to implement a simple probability in php
This article mainly introduces a simple probability-related code implemented in PHP. It analyzes the principles and usage skills of probability statistics through numerical operations. Friends in need can refer to it
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:
19589
29795
50615
The key is mt_rand(0,100)
Pass $a $b The number of occurrences of $c reflects the probability
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's learning.
Related recommendations:
Detailed explanation of simple digital paging function in PHP
php Implementation of forced download file function Method
phpMethod of downloading various files based on header function
The above is the detailed content of How to implement a simple probability in php. For more information, please follow other related articles on the PHP Chinese website!