Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: random pairs

by jwkrahn (Monsignor)
on Jul 14, 2012 at 09:32 UTC ( #981797=note: print w/replies, xml ) Need Help??


in reply to random pairs

#!/usr/bin/perl use warnings; use strict; use List::Util 'shuffle'; my @random; LOOP: { @random = shuffle 0 .. 99; my %unique; for ( 0 .. $#random ) { redo LOOP if $_ == $random[ $_ ] || ++$unique{ $_ < $random[ $ +_ ] ? "$_,$random[$_]" : "$random[$_],$_" } > 1; } } my @pairs = map [ $_, $random[ $_ ] ], 0 .. $#random;

Replies are listed 'Best First'.
Re^2: random pairs
by CountZero (Bishop) on Jul 14, 2012 at 12:12 UTC
    You assume that the "predetermined list" is an unbroken sequence of integers from 0 to x. How will you do if it is just a set of integers with duplicates and gaps?

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://981797]
help
Chatterbox?
[james28909]: i guess i should have done it in perl. i bet it woulnt have taken me 5 hours to figure out haha
[choroba]: In the end, I was able to upgrade Perl from 5.8.3 to 5.22 and install Net::SFTP::Foreign , at least for the task involved
[james28909]: what would be the best way to capture that stream with perl? ffmpeg args -rtp rtp://127.0.0.1?
[LanX]: if I was forced to talk about all security risks I encountered oO
[james28909]: if i did that with ffmpeg, i could then listen on the port with perl right?
[LanX]: one of my clients filtered a menu linking to Web pages according to user rights. .. but he didn't secure the access to those unlisted pages

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2017-05-22 21:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?