Probability calculation PHP Lucky Star

Source: Internet
Author: User
Specify a probability (here is the number of points) to determine whether an event has occurred. it can be used to randomly generate website lucky stars based on the number of points you get (note: There is a word here ). & lt ;? Php/** @ title: PHP lucker @ version: 1.00 @ license: BSD @ author: axgle */$ bllu

Specify a probability (here is the number of points) to determine whether an event has occurred.
It can be used to randomly generate website lucky stars based on the number of points you get (note: There is a word here ).
/**
@ Title: PHP Lucky Star (lucker)
@ Version: 1.00
@ License: BSD
@ Author: axgle
*/

$ Bl = lucker (50); // 50% likelihood
Var_dump ($ bl );

Function lucker ($ dot ){
$ Dot = intval ($ dot );
$ Dot = max ($ dot, 0); // min dot = 0
$ Dot = min ($ dot, 100); // max dot = 100

$ One = revert (1,100 );
$ Total = range (1, 1,100 );
Shuffle ($ total );

$ Range = array ();
For ($ I = 0; $ I <$ dot; $ I ++ ){
$ Range [] = $ total [$ I];
}
Return in_array ($ one, $ range );
}
?>

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.