- array_diff_assoc: documentation ( source)
- shuffle: documentation ( source)
- define: documentation ( source)
- rand: documentation ( source)
- srand: documentation ( source)
<?php
define('TEST_VALUE_COUNT', 10);
srand(15);
$values = array();
for ($i = 0; $i < TEST_VALUE_COUNT; $i++) {
$values[] = rand();
}
srand(15);
foreach($values as $key => $value) {
if ($value !== rand()) {
print "Bad value at " . $key;
exit;
}
}
echo "All were the same in " . count($values) . " values\n";
$valuesShuffled = $values;
srand(15);
shuffle($valuesShuffled);
srand(15);
shuffle($values);
if (count(array_diff_assoc($values, $valuesShuffled)) == 0) {
echo "Array was the same after a seeded shuffle";
} else {
echo "Array was not the same after a seeded shuffle\n";
}