Home  >  Article  >  php教程  >  php实现简单洗牌算法

php实现简单洗牌算法

WBOY
WBOYOriginal
2016-06-06 20:30:301461browse

本篇文章是对php实现简单洗牌算法的程序代码进行了详细的分析介绍,需要的朋友参考下

如下所示:

复制代码 代码如下:


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

$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;
}
?>

,美国服务器,虚拟主机,虚拟主机
Statement:
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