[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Shufflebug



>I believe your shuffle has a bug (at least if it's meant to produce a
>truly shuffled deck).  

I write a card shuffler that does the following:

  # @cards is first half, @half is second half
  @half = splice @cards, 26;
  @shuffled = ();

  while (@cards || @half) {
    if (@cards) {
      $move = 1 + int rand (4 > @cards ? @cards : 4);
      push @shuffled, splice @cards, -$move;
    }
    if (@half) {
      $move = 1 + int rand (4 > @half ? @half : 4);
      push @shuffled, splice @half, -$move;
    }
  }

Perhaps that's stupid of me, but I think it's more like the real shuffling
that occurs.  So shoot me.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe