Home > Backend Development > PHP Tutorial > How to implement a simple probability in php

How to implement a simple probability in php

墨辰丷
Release: 2023-03-29 11:38:02
Original
1656 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 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 . &#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)

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!

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