- var_dump: documentation ( source)
- in_array: documentation ( source)
- rand: documentation ( source)
<?php
$maxId = 10;
$n = 10;
// If there are less urls in the db then required, lower the requirements
$n = $maxId < $n ? $maxId : $n;
$randomIds = [];
while (count($randomIds) < $n) {
$randomId = rand(1, $maxId);
if (!in_array($randomId, $randomIds)) {
$randomIds[] = $randomId;
}
}
var_dump($randomIds);