Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Random Couple Script

by thospel (Hermit)
on Nov 09, 2004 at 12:02 UTC ( [id://406314]=note: print w/replies, xml ) Need Help??


in reply to Re: Random Couple Script
in thread Random Couple Script

Heh, this code is the most interesting of the lot since it *seems* wrong.

If the splice line had been

splice @array, rand(1+@array ), 0, $_ for map{ /^..(.*$)/ } <DATA>;
it would obviously have been fair. Now it seems to have a slight preference for left, so that makes you worry that e.g. maybe the last two elements don't get paired often enough. But that impression is wrong. The bias only causes the order inside one pair to be lopsided. The element inserted first becomes the last element in @array, and will remain last during the loop. The other n-1 elements will get a fair shuffle. So after pairing the result is fair, but the first element inserted will always be last in its pair.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-04-26 03:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found