in reply to removing the goto
I'd refactor the loop to eliminate the goto, the label, most of the nesting, and to make the intent a little clearer:
foreach my $i (0..$maxclients-1) { $selected[$i] = $weighteddiv[int rand @weighteddiv]; next if $i == 0; # Check for duplicates redo if grep {$selected[$i] == $selected[$_]} 0 .. $i-1; }
Update: s/next if/last if/ - bug pointed out by TimToady
Update: removed while loop - issue pointed out by TimToady
fixed bug due to next in foreach modified statement
fixed domain for rand - issue pointed out by TimToady
|
|---|