PHP implementation of a simple probability-related code, PHP probabilistic Code _php Tutorial

Source: Internet
Author: User
Tags php database php regular expression

PHP implementation of a simple probability-related code, PHP probability code


This paper describes a simple probabilistic correlation code for PHP implementations. Share to everyone for your reference, 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 $a. '
'; Echo $b. '
'; Echo $c. '

Output Result:

19589
29795
50615

Key in Mt_rand (0,100)

Probability is represented by the number of occurrences of a $ A $b $c

Add: The above code is not typeset, it seems a little difficult to read, fortunately the code is not many. Small series here is recommended a site of the PHP format landscaping tools to help you in the future of PHP programming code layout, increase the readability of the code:

PHP Code online format Beautification tool:

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

In addition, because PHP is a C language style, the following tool can also be used to implement the PHP code format :

C Language Style/html/css/json code formatting beautification tool:
Http://tools.jb51.net/code/ccode_html_css_json

More interested in PHP related content readers can view the site: "PHP Math Skills Summary", "PHP operation Office Document Skills Summary (including word,excel,access,ppt)", "PHP array" operation Skills Daquan, " PHP Sorting algorithm Summary, "PHP Common traversal algorithm and skills summary", "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", "PHP Regular Expression Usage summary", "PHP operation and operator Usage Summary", "PHP string Usage Summary" and " A summary of common PHP database operation techniques

I hope this article is helpful to you in PHP programming.

http://www.bkjia.com/PHPjc/1133049.html www.bkjia.com true http://www.bkjia.com/PHPjc/1133049.html techarticle PHP Implementation of a simple probability-related code, PHP probability code This article describes a PHP implementation of a simple probability-related code. Share to everyone for your reference, as follows: PHPF ...

  • 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.