3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo PHP_INT_SIZE . "\n"; function pickBitsFromInput($val, $amtBits, $arraySize) { $itrs = ceil($amtBits / 8); $results = []; $ret = []; for ($i = 0; $i < $itrs; $i++) { $val = hash('sha256', $val, true); $results = array_merge($results, unpack('L8', $val)); } for ($i = 0; $i < $amtBits; $i++) { $ret[] = $results[$i] % $arraySize; } return $ret; } var_dump(pickBitsFromInput('woohoo', 9, 1000000));

preferences:
61.64 ms | 402 KiB | 5 Q