Logo

Programming-Idioms

History of Idiom 11 > diff from v19 to v20

Edit summary for version 20 by :

Version 19

2015-09-04, 09:24:42

Version 20

2015-09-06, 14:30:32

Idiom #11 Pick a random element from a list

List x must be non-empty.

Idiom #11 Pick a random element from a list

List x must be non-empty.

Code
my @list = ('a', 'list', 'of', 'random', 'item's);

print $list[ rand(@list) ], "\n";
Code
my @list = ('a', 'list', 'of', 'random', 'item's);

print $list[ rand(@list) ], "\n";
Comments bubble
In scalar context (such as the call to rand), an array evaluates to the *length*.
Comments bubble
In scalar context (such as the call to rand), an array evaluates to the length.