PHP code example of jefhar / fisher-yates

1. Go to this page and download the library: Download jefhar/fisher-yates library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jefhar / fisher-yates example snippets


use Lmc\FisherYates\FisherYates;

$itemsToShuffle = ['a', 'b', 'c', 'd', 'e'];

$fy = new FisherYates($itemsToShuffle);

$result = $fy->shuffle();

use Lmc\FisherYates\FisherYates;

$seed = 123_456_789;
$itemsToShuffle = ['a', 'b', 'c', 'd', 'e'];
$fy = new FisherYates($itemsToShuffle);

var_dump($fy->shuffle($seed));

array(5) {
  [0]=>
  string(1) "d"
  [1]=>
  string(1) "a"
  [2]=>
  string(1) "b"
  [3]=>
  string(1) "e"
  [4]=>
  string(1) "c"
}