时间:2021-07-01 10:21:17 帮助过:4人阅读
01
02
/**
03
* @author phpman.cn
04
* @date 2012/12/04
05
* @todo 简单洗牌算法
06
*/
07
08
$card_num
=54;
//牌数
09
print_r(wash_card(
$card_num
));
10
11
function
wash_card(
$card_num
)
12
{
13
$cards
=
$tmp
=
array
();
14
for
(
$i
=0;
$i
<
$card_num
;
$i
++){
15
$tmp
[
$i
]=
$i
;
16
}
17
18
for
(
$i
=0;
$i
<
$card_num
;
$i
++){
19
$index
=rand(0,
$card_num
-
$i
-1);
20
$cards
[
$i
]=
$tmp
[
$index
];
21
unset(
$tmp
[
$index
]);
22
$tmp
=
array_values
(
$tmp
);
23
}
24
return
$cards
;
25
}
26
?>
http://www.bkjia.com/PHPjc/735158.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/735158.htmlTechArticle来源:http://phpman.cn/?p=37 标签: 无 代码片段 (1) [代码] [PHP]代码 view source print? 01 ?php 02 /** 03 * @author phpman.cn 04 * @date 2012/12/04 05 * @todo 简单洗牌...