Home > Backend Development > PHP Tutorial > Implementing a simple shuffling algorithm in php_PHP tutorial

Implementing a simple shuffling algorithm in php_PHP tutorial

WBOY
Release: 2016-07-21 15:05:13
Original
984 people have browsed it

As shown below:

Copy code The code is as follows:

/**
* Simple shuffling algorithm
* /

$card_num=54; //Number of cards
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);                                          index];
unset($tmp[$index]);
$tmp=array_values($tmp);
}
return $cards;
}
?>

http://www.bkjia.com/PHPjc/327706.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327706.htmlTechArticle is as follows: Copy the code as follows: ?php /*** Simple shuffling algorithm*/ $card_num=54; //Number of cards print_r(wash_card($card_num)); function wash_card($card_num) { $cards=$tmp=array()...
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