in reply to Re: Rolling For Initiative
in thread Rolling For Initiative
sub shuffle { # Move each element to a random location my $arrayref = shift; my $temp; for (my $i = 0; $i < scalar @$arrayref; $i++) { my $r = rand( scalar @$arrayref); $temp = $arrayref->[$r]; $arrayref->[$r] = $arrayref->[$i]; $arrayref->[$i] = $temp; } }
I do recall that day when all the weighted selection questions came out, but this one is somewhat unique in that every item must be selected... it is only the order of selection that needs to be randomized.
PS:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Rolling For Initiative
by kennethk (Abbot) on Dec 19, 2008 at 17:43 UTC | |
|
Re^3: Rolling For Initiative
by gone2015 (Deacon) on Dec 20, 2008 at 20:55 UTC |