PHP implements double color ball algorithm code

小云云
Release: 2023-03-20 10:04:02
Original
10137 people have browsed it

This article mainly introduces the two-color ball algorithm implemented in PHP, involving PHP array traversal, random numbers and other related operation skills. Friends who need it can refer to it. I hope it can help everyone.


<?php
function DoubleBall(){
  $sysBlueball = mt_rand(1,16);
  $sysRedball = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33);
  $result = array();
  for($i=0; $i<6; $i++)
  {
    while(true)
    {
      $index = mt_rand(0,32);
      if($sysRedball[$index] != 0){
        $result[$i] = $sysRedball[$index];
        $sysRedball[$index] = 0;
        break;
      }
    }
   }
   $result = implode(&#39;,&#39;,$result);
   echo &#39;你选择的篮球为:&#39;.$sysBlueball.&#39;&#39;;
   echo &#39;你选择的红球为:&#39;.$result.&#39;&#39;;
}
DoubleBall();
?>
Copy after login

Running results:


你选择的篮球为:3你选择的红球为:29,11,26,14,9,24
Copy after login

Related recommendations:

JS implementation Double color ball function code sharing

2 ways to randomly generate welfare lottery double color ball numbers using php_PHP tutorial

Use php to randomly generate welfare lottery numbers 2 methods of double color ball numbers

The above is the detailed content of PHP implements double color ball algorithm code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!