Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the function of large turntable by php

Shulou Source: shulou.com Published: 2022-06-02 14:52:27 10月01日 Update

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

Tags: Awards arrays probabilities turntables functions situations codes content integers more computers knowledge practicality achievement next flash drives backstage dilemmas prizes reality Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Linux Apple MariaDB Xiaomi