[Wellington-pm] Select at random from a list

Philip Plane philip at xinqu.net
Sun Jul 16 16:59:20 PDT 2006

On Sat, 15 Jul 2006, Jacinta Richardson wrote:

> 	$mp3 = $playlist[int(rand(scalar(@playlist)))];
> can also be written as:
> 	$mp3 = $playlist[ rand(@playlist) ];

Yes, I could do that. Turns out I can also do:

 $mp3 = $playlist[rand @playlist];

And even better I can correct for the off by one bug that I'd deliberately
put in to see if you were all awake :)

 $mp3 = $playlist[rand @playlist +1];

Philip Plane    _____   philip at xinqu.net
  ---------------( )---------------
Glider pilots have no visible means of support

More information about the Wellington-pm mailing list