Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Add a fixed number of unique elements to hash

by jwkrahn (Abbot)
on Mar 05, 2023 at 22:02 UTC ( [id://11150763]=note: print w/replies, xml ) Need Help??


in reply to Re: Add a fixed number of unique elements to hash
in thread Add a fixed number of unique elements to hash

If shuffle takes too long you could do this:

sub uploadPlaylist { for my $i ( 1 .. $numOfRandFiles ) { $playList{ splice @audioFiles, int rand @audioFiles, 1 } = $i; } }
Naked blocks are fun! -- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re^3: Add a fixed number of unique elements to hash
by Vasek (Acolyte) on Mar 05, 2023 at 22:55 UTC
    Thx a lot jwkrahn! Splice is the key for me. Other solutions that use "factory" modules are out of the question, i.e. this machine is running perl 5.004, which has quite a few syntactical differences compared to today's perl versions. Of course, I could try transplanting the modules, but my only connection to this old SGI machine is via nfs sharing over a software half-speed network interface (since it can no longer be communicated with securely with today's settings).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-24 16:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found