public function shuffle(bool $secure = false, array $array = null): self
    {
        if ($array === null) {
            $array = $this->getArray();
        }

        if ($secure !== true) {
            /** @noinspection NonSecureShuffleUsageInspection */
            \shuffle($array);
        } else {
            $size = \count($array, \COUNT_NORMAL);
            $keys = \array_keys($array);
            for ($i = $size - 1; $i > 0; --$i) {
                try {
                    $r = \random_int(0, $i);
                } catch (\Exception $e) {
                    /** @noinspection RandomApiMigrationInspection */
                    $r = \mt_rand(0, $i);
                }
                if ($r !== $i) {
                    $temp = $array[$keys[$r]];
                    $array[$keys[$r]] = $array[$keys[$i]];
                    $array[$keys[$i]] = $temp;
                }
            }

            // reset indices
            $array = \array_values($array);
        }

        foreach ($array as $key => $value) {
            // check if recursive is needed
            if (\is_array($value) === true) {
                $array[$key] = $this->shuffle($secure, $value);
            }
        }

        return static::create(
            $array,
            $this->iteratorClass,
            false
        );
    }
public function shuffle(bool $secure = false, array $array = null): self
    {
        if ($array === null) {
            $array = $this->getArray();
        }

        if ($secure !== true) {
            /** @noinspection NonSecureShuffleUsageInspection */
            \shuffle($array);
        } else {
            $size = \count($array, \COUNT_NORMAL);
            $keys = \array_keys($array);
            for ($i = $size - 1; $i > 0; --$i) {
                try {
                    $r = \random_int(0, $i);
                } catch (\Exception $e) {
                    /** @noinspection RandomApiMigrationInspection */
                    $r = \mt_rand(0, $i);
                }
                if ($r !== $i) {
                    $temp = $array[$keys[$r]];
                    $array[$keys[$r]] = $array[$keys[$i]];
                    $array[$keys[$i]] = $temp;
                }
            }

            // reset indices
            $array = \array_values($array);
        }

        foreach ($array as $key => $value) {
            // check if recursive is needed
            if (\is_array($value) === true) {
                $array[$key] = $this->shuffle($secure, $value);
            }
        }

        return static::create(
            $array,
            $this->iteratorClass,
            false
        );
    }
public function shuffle ( bool $ secure = false , array $ array = null ) : self { if ( $ array === null ) { $ array = $ this -> getArray ( ) ; } if ( $ secure !== true ) { /** @noinspection NonSecureShuffleUsageInspection */ \ shuffle ( $ array ) ; } else { $ size = \ count ( $ array , \ COUNT_NORMAL ) ; $ keys = \ array_keys ( $ array ) ; for ( $ i = $ size - 1 ; $ i > 0 ; -- $ i ) { try { $ r = \ random_int ( 0 , $ i ) ; } catch ( \ Exception $ e ) { /** @noinspection RandomApiMigrationInspection */ $ r = \ mt_rand ( 0 , $ i ) ; } if ( $ r !== $ i ) { $ temp = $ array [ $ keys [ $ r ] ] ; $ array [ $ keys [ $ r ] ] = $ array [ $ keys [ $ i ] ] ; $ array [ $ keys [ $ i ] ] = $ temp ; } } // reset indices $ array = \ array_values ( $ array ) ; } foreach ( $ array as $ key => $ value ) { // check if recursive is needed if ( \ is_array ( $ value ) === true ) { $ array [ $ key ] = $ this -> shuffle ( $ secure , $ value ) ; } } return static :: create ( $ array , $ this -> iteratorClass , false ) ; }
Shuffle the current array.

@param bool  $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p>
@param array $array  [optional]

@return static
<p>(Immutable)</p>
Shuffle the current array .