Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Pulling random elements from hash

by Aristotle (Chancellor)
on Jun 22, 2003 at 02:00 UTC ( [id://267899]=note: print w/replies, xml ) Need Help??


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...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://267899]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-26 06:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found