Please try these constructed list instructions:
Begin Unverified Perl
# Parameters
my $plist = 'list1';
my @items = (1, 2, 3, 4);
# Run
ADD($plist);
foreach my $item (@items) {
REMOVE($plist, $item);
}
RANDOMIZE();
my $len = LISTLENGTH($plist) - scalar(@items);
my @bannedInserts = ();
while (scalar(@items)) {
# Choose item to add
my $addIndex = int(rand(scalar(@items)));
my $addItem = $items[$addIndex];
splice(@items, $addIndex, 1);
# Insert
my @options = ();
for (my $i = 1; $i <= $len + 1; $i++) {
my $banned = 0;
for (my $j = 0; $j < scalar(@bannedInserts) && !$banned; $j++) {
$banned = $bannedInserts[$j] == $i;
}
if (!$banned) {
push(@options, $i);
}
}
my $insert = $options[int(rand(scalar(@options)))];
INSERT($insert, $plist, $addItem);
$len++;
# Update banned indices
for (my $i = 0; $i < scalar(@bannedInserts); $i++) {
if ($bannedInserts[$i] > $insert) {
$bannedInserts[$i] = $bannedInserts[$i] + 1;
}
}
push(@bannedInserts, $insert);
push(@bannedInserts, $insert + 1);
}
End Unverified
Line 3 must be updated with the name of the predefined list.
If the number of these special items were made much larger, there are some optimizations that would be prudent to make. But the performance ought to be sufficient for this case.