3v4l.org

run code in 300+ PHP versions simultaneously
<?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); ?>

preferences:
39.32 ms | 402 KiB | 5 Q