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

Re: [FWP] Perl Card Games



On Tue, 3 Aug 1999, Amir Karger wrote:
> More interesting still, (using 26 numbers for easier readability than 50)
> 
>     fermi2:~>perl
>     print (join(' ', sort {$a <=> (int rand $l)} (1..$l)),"\n\n");
>     print (join(' ', sort {$a <=> (int rand $l)} (1..$l)),"\n");
>     1 22 26 4 2 3 25 5 19 6 20 24 12 13 8 10 11 7 23 21 14 9 18 16 17 15
> 
>     1 2 3 7 4 26 8 6 14 5 9 25 24 23 15 11 13 10 12 21 17 22 19 16 20 18

Well, I have punched out a little rather uninteresting bit of code,
managing to use both $a, $b and a random number to do comparisons with.
One-pass shuffle, but more using passes definitely works better.


	@array=(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20); 
	$t=int(rand(1*@array)+0.5);
	@array=sort {($a <=> $t) <=> ($t <=> $b)} @array;

Mainly this seems to get around the issue of 1 mostly being in the first
position of the shuffled array. 

Ciao


--
+======================+======================================
|Zak McGregor	       |	There has been an alarming
+----------------------+	increase in the number of
|Infoline South Africa |	things you know nothing about.
+======================+======================================




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