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

Re: [FWP] Perl Card Games



> 
> > 	@shuffled = ();
> > 	push @shuffled, splice @src, rand(@src), 1 while @src;
> 
> OK. How about 
> 
> %a = map { $_ => undef} (0..51);
> @shuffled = @src[keys %a];
> 
> I guess that might make playing a second game rather boring, but it's, well,
> *kind of* random. I had the severely evil idea of:
> 
> @shuffled = sort {rand - .5} @shuffled;
> 

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


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