PHP 8.5.0 Alpha 2 available for testing

Voting

: eight minus eight?
(Example: nine)

The Note You're Voting On

DiosDe
3 years ago
implementation of shuffle() using random_int()

<?php

function random_int_shuffle ( array $array ): array
{
$array = array_values($array);

$result = [];
$skip_indexes = [];

$sizeof_array = count($array);

for (
$i = 0; $i < $sizeof_array; $i++ )
{
do
{
$random_index = random_int(0, $sizeof_array);
} while (
in_array($random_index, $skip_indexes) );

$skip_indexes[] = $random_index;
$result[] = $array[$random_index];
}

return
$result;
}
?>

<< Back to user notes page

To Top