- array_slice: documentation ( source)
- print_r: documentation ( source)
- shuffle: documentation ( source)
- in_array: documentation ( source)
- range: documentation ( source)
<?php
$numbers = range(1, 2,3); // numbers to pick from
$length = 2; // amount of items in the set
$sets_amount = 100; // amount of sets you want to generate
$existing = array(); // where we store existing sets
$shuffle_period = count($numbers) - $length - 1; // how often we re-randomize the elements
$j = 0;
for ($i = 0; $i < $sets_amount; $i++, $j++) {
if (!($i % $shuffle_period)) {
shuffle($numbers); // randomize at first go and on $shuffle_period
$j = 0;
}
do {
$arr = array_slice($numbers, $j, $length);
} while (in_array($arr, $existing));
$existing[] = $arr;
}
print_r($existing);
?>