Php implements a simple probability-related code and php probability code.

Source: Internet
Author: User

Php implements a simple probability-related code and php probability code.

This example describes a simple probability-related Code implemented by php. We will share this with you for your reference. The details are as follows:

<? Phpfor ($ 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 $. '<br/>'; echo $ B. '<br/>'; echo $ c. '<br/>';?>

Output result:

19589
29795
50615

The key lies in mt_rand (0,100)

The probability is expressed by the number of occurrences of $ a $ B $ c.

Supplement: The above code is not typographical and seems a little hard to read. Fortunately, there are not many codes. Here, we recommend a php formatting and beautifying typographical tool on this site to help you typeset code in future PHP programming and increase the readability of the Code:

Php code online formatting and beautification tools:

Http://tools.jb51.net/code/phpformat

In addition, because php belongs to the C language style, the following tool can also format php code:

C language style/HTML/CSS/json code formatting and beautification tools:
Http://tools.jb51.net/code/ccode_html_css_json

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.