Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Re: picking multiple random elements out of an array

by dws (Chancellor)
on Feb 03, 2002 at 23:09 UTC ( [id://143155]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re: picking multiple random elements out of an array
in thread picking multiple random elements out of an array

Here's a "variation of the above" code fragment from an ancient script. It produces a set of numbers which can be used as indices in an array slice.
# @indices = randomsubset(scalar @array, $size_of_subset); sub randomsubset { my @indices = 0 .. $_[0] - 1; my @subset = (); push @subset, splice(@d, int rand @indices, 1) for 1 .. @_[1]; @subset; } print join (" ", randomsubset(50,5)), "\n";
(The overly specific name indicates sloppy thinking on my part, for which I plead guilty.)

IIRC, there's something equivalent in the Cookbook.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://143155]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.