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

Re: [FWP] Perl Card Games



John Porter <jdporter@min.net> writes:

> Sort by random strings:  # UNTESTED CODE
> 
> @shuffled =
> 	map  { (split)[1] }
> 	sort 
> 	map  { join ' ', randstring(), $_ }
> 	( 0 .. 51 );
> 
> sub randstring {
>   join '', map { chr(ord('a')+int(rand(26))) } ( 0 .. int(rand(4))+3 )
> }
> 
> __END__ 
> John Porter

@cards = (0 .. 51); # or any number of them
$passes = 1; # one pass should be sufficient for all but the most paranoid
$cards[$_ % @cards] = $cards[rand(@cards) % @cards] foreach 0 .. ($passes * @cards - 1);

I love infix foreach.  It's lots of fun!

Chip

-- 
Chip Turner                   chip@ZFx.com
                              Programmer, ZFx, Inc.  www.zfx.com
                              PGP key available at wwwkeys.us.pgp.net

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