- var_dump: documentation ( source)
- hash: documentation ( source)
- array_merge: documentation ( source)
- ceil: documentation ( source)
- unpack: documentation ( source)
<?php
echo PHP_INT_SIZE . "\n";
function pickBitsFromInput($val, $amtBits, $arraySize)
{
$itrs = ceil($amtBits / 8);
$results = array();
$ret = array();
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));