I think I've got a solution that should work to meet these constraints.
function nextList($last) {
$index = rand(1,50); // don't select first or last elements
$out = array();
do {
list($value) = array_splice($last, $index, 1);
$out[] = $value;
$maxLoop = count($last);
do {
$newIndex = array_rand($last);
} while ($newIndex == $index && --$maxLoop);
$index = $newIndex;
} while (count($last) > 1);
$out[] = $last[0];
return $out;
}
Used as follows:
$first = range(0, 51);
shuffle($first);
$second = nextList($first);
$third = nextList($second);
// etc.
This works on the basis that, for each element it adds to the new array, it is not proceeded by the same element that proceeds it in the last array.
For example, if the last array had, somewhere, the values 43,12,13...
, and we add the element 43
to the new array, then we ensure that the next element is any element EXCEPT 12
. With this logic, it should be impossible to get the same repeated sequences.
It also ensures that the first element is neither the first nor last element of the last array, however, making this constraint work also for the last element of the array would be a lot more difficult.
EDIT
I was actually able to use the check
function given in Hendriq's answer to check whether this solution works, and it seems to always return a valid new list which does not contain a sequence from the last array =]