Or a question about the probability of PHP, the solution says

Source: Internet
Author: User
Or is the probability of PHP problem solved by saying
Probability calculation function, a lot of online search is this, but do not understand this function, how to solve the process is ~
This array is the ID and the corresponding probability.

Array
(
???? [1] = 1
???? [2] = 5
???? [3] = 10
???? [4] = 12
???? [5] = 22
???? [6] = 50
)

Why is it possible to get the ID of the probability prize?? Get_rand ($arr);
















}

Share to: more


------Solution--------------------
Suppose a:20% b:30% c:50%
$r =rand (1,100)

$r <=20 A Award
20< $r <= (20+30) B Award
(20+30) <= $r C Award
  • 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.