來源: http://phpman.cn/?p=37
標簽: <無>
01
<?php
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
?>