Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: What I am missing here

by lidden (Deacon)
on Mar 20, 2012 at 20:46 UTC ( #960654=note: print w/ replies, xml ) Need Help??


in reply to What I am missing here

I think your shuffle is buggy. Use the built in shuffle instead.

use List::Util; # ... snip ... @deck = List::Util::shuffle @deck;


Comment on Re: What I am missing here
Select or Download Code
Re^2: What I am missing here
by JavaFan (Canon) on Mar 20, 2012 at 22:26 UTC
    The shuffle is "buggy" only in the sense that it isn't fair. (Not every permutation will happen with equal probability). Replacing it with a fair algorithm doesn't make the OPs problem go away.
Re^2: What I am missing here
by Marshall (Prior) on Mar 21, 2012 at 04:01 UTC
    This is slightly different that the fisher_yates_shuffle algorithm.

    At the root of the matter, rand() is not random and has a odd,even,odd,even bias - or at least common implementations do. There are better "pseudo random number generators" than rand(). They are much more computationally expensive and I think outside of the scope of this thread.

Re^2: What I am missing here
by heatblazer (Scribe) on Mar 21, 2012 at 05:45 UTC

    Well, I may not agree here. "Buggy" if it messes some elements in the deck by either copy them in the swap process. However I`ve tested it, and it`s OK, yes I am missing the srand(seed) but my algorithm is working since it never goes out of range and in worst case it can just swap two similar elements like card2 with card2 but it`s no error at all and it`s quite possible in real life shuffle too.

    The awkward moment you shuffle and you get 3 times the same cards to piss everybody out on the table... well it`s no algorithm for a lame shuffler, better never gave him/her to pass cards again!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2014-07-31 02:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (244 votes), past polls