On Thu, Nov 29, 2001 at 06:36:06AM +0100, Philip Newton wrote:
> On Wed, 28 Nov 2001 12:46:06 -0600, [EMAIL PROTECTED] (Andy Bach)
> wrote:
>
> > Thanks much. I thought there might be related technique for getting a
> > rand element from an array, but we know the array length so ... this
> > (from above) did help w/ my getting all the elements in a random order, i.e.:
> > while ( @arr ) {
> > $pos = rand($#arr);
> > $val = splice @arr, $pos, 1;
> > print "is: $val\n";
> > }
>
> Obi-Wan error in there? I think you need rand(@arr), or you're never
> going to get the last element (since rand($#arr) always is < $#arr).
Actually, the last element will always come out last, because rand(0) is
the same as rand(1).
Ronald