php实现简单洗牌算法

yipeiwu_com6年前PHP代码库
如下所示:
复制代码 代码如下:

<?php
 /**
  * 简单洗牌算法
  */

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

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

     for($i=0;$i<$card_num;$i++){
         $index=rand(0,$card_num-$i-1);
         $cards[$i]=$tmp[$index];
         unset($tmp[$index]);
         $tmp=array_values($tmp);
     }
     return $cards;
 }
 ?>

相关文章

php中file_get_contents与curl性能比较分析

php中file_get_contents与curl性能比较分析

本文实例讲述了php中file_get_contents与curl性能比较分析。分享给大家供大家参考。具体如下: 在php中如果不仔细的去分析性能会发现file_get_contents...

使用bcompiler对PHP文件进行加密的代码

使用说明: //载入函式 include_once('phpCodeZip.php'); //建立加密文件(sourceDir要加密的php文件目录,targetDir加密后的文件目录)...

php查询whois信息的方法

本文实例讲述了php查询whois信息的方法。分享给大家供大家参考。具体如下: 这里使用php通过查询whois信息的网站列表进行查询 function whois_query($d...

php 时间计算问题小结

具体如下: 1>如我们知道开始时间,要加减一个时间,得出一个结果时间,可以用以下代码 $time1='2008-10-1 12:30:30'; echo date('Y-m-d H...

PHP中关键字interface和implements详解

PHP 接口 PHP 类是单继承,也就是不支持多继承,当一个类需要多个类的功能时,继承就无能为力了,为此 PHP 引入了类的接口技术。 如果一个抽象类里面的所有方法都是抽象方法,且没...