Home > Backend Development > PHP Tutorial > php实现简单洗牌算法_php技巧

php实现简单洗牌算法_php技巧

WBOY
Release: 2016-05-17 09:00:37
Original
861 people have browsed it

如下所示:

复制代码 代码如下:

 /**
  * 简单洗牌算法
  */

 $card_num=54; //牌数
 print_r(wash_card($card_num));

 function wash_card($card_num)
 {
     $cards=$tmp=array();
     for($i=0;$i         $tmp[$i]=$i;
     }

     for($i=0;$i         $index=rand(0,$card_num-$i-1);
         $cards[$i]=$tmp[$index];
         unset($tmp[$index]);
         $tmp=array_values($tmp);
     }
     return $cards;
 }
 ?>
Related labels:
php
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