In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "how to realize the big turntable function of php". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
Php to achieve the function of the large turntable method: 1, assemble the award array, code such as "$prize_arr = array(...) ";2, calculate the probability of winning;3, return to the winning situation.
Operating environment: Windows 7 system, PHP7.1 version, DELL G3 computer
How does php implement the large turntable function?
PHP implementation of the big turntable lottery algorithm
Process:
1. Assemble the prize array, 2. Calculate the probability, 3. Return the winning situation
The code is as follows: Winning probability ' v ' can be set in the background, passed to this method, pay attention to integer
function get_gift(){ //Assemble award array //award id, prize, probability $prize_arr = array( '0' => array ('id '=>1,'prize'=>' tablet','v'=>0), '1' => array ('id '=>2,'prize'=>' digital camera','v'=>0), '2' => array ('id '=>3,'prize'=>' slightly device','v'=>0), '3' => array ('id '=>4,'prize'=>'4G USB drive','v'=>5), '4' => array('id'=>5,'prize'='10Q','v'=>0), '5' => array ('id '=>6,'prize'=>' empty prize','v'=>5), ); foreach ($prize_arr as $key => $val) { $arr[$val <$'id ']] = $val <$'v'];//Probability array } $rid = $this->get_rand($arr); //get prize id based on probability $res <$'yes '] = $prize_arr[$rid-1]<$'prize']; //winning prize unset($prize_arr[$rid-1]); //remove the winning item from the array, leaving the unwinning item shuffle($prize_arr); //shuffle array for($i=0;$i $proCur) { $randNum = mt_rand(1, $proSum); //Returns a random integer if ($randNum
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.