[Omaha.pm] Pick a random array element ... beware the web experts :)

Dave M dave.nerd at gmail.com
Mon Oct 23 14:39:24 PDT 2006


On 10/23/06, Jay Hannah <jhannah at omnihotels.com> wrote:
>
> This is a great little explanation I hit Googling for how to pick a
> random array element today:
>
> http://www.webmasterworld.com/forum13/668.htm
>
> Except.... at the end when he shows the one liner:
>
> #now all together
> @a = ($text1,$text2,$text3,...,'unused element');
> print $a[int rand($#a)];
>
> It's wrong. The correct print statement is:
>
> print $a[int rand($#a + 1)];
>
Just to be difficult :), what's wrong with this:

print "rand = ", $a[int rand(@a)], "\n";

?


More information about the Omaha-pm mailing list