in reply to Re: Pulling random elements from hash
in thread Pulling random elements from hash

$array[int(rand(scalar(@array)))];
Of course you can just write
$array[rand @array];
which will do exactly the same thing and is a bit less distracting to read.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re^2: Pulling random elements from hash
by sgifford (Prior) on Jun 22, 2003 at 02:15 UTC
    I saw that in another post. Do you know why this is? It seems like rand is unlikely to pick an integer, and $array[3.14159] seems nonsensical, but I tried it and it works...