Consider this code :
<?php
$j = 0;
while ($j++<10) {
        $i = 0;
        $s = "abcdef";
        $a = array();
        while ($i++<720) {
                $a[] = str_shuffle($s);
        }
        var_dump(count(array_unique($a)));
        $i = 0;
        $ar = array('a','b','c','d','e','f');
        $c = array();
        while ($i++<720) {
                $b = $ar;
                shuffle($b);
                $c[] = implode('',$b);
        }
        var_dump(count(array_unique($c)));
        echo "\n";
}
?>
I am trying to compare. On my machine i got this :
int(444)
int(453)

int(447)
int(454)

int(455)
int(451)

int(444)
int(464)

int(454)
int(451)

int(455)
int(465)

int(454)
int(464)

int(450)
int(455)

int(455)
int(450)

int(458)
int(446)

In 4 of 10 str_shuffle() shuffles better than array_shuffle().
It looks like that the unique combinations depend on the machine because
this test is performed on my work machine under vmware.
I said that the shuffling method is like shuffle()'s in 4.2.1 but like.
In 4.2.1 it was just php_rand(TSRMLS_C) %2 1:-1
I tried first with this and on every 3-4 runs I got the same string, so I
decided
to modify. As far as I can see from my tests the result is not bad compared
to
shuffle().

Best regards
Andrey Hristov


----- Original Message -----
From: "Adam Maccabee Trachtenberg" <[EMAIL PROTECTED]>
To: "Andrey Hristov" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Wednesday, September 25, 2002 10:11 PM
Subject: Re: [PHP-CVS] cvs: php4 /ext/standard basic_functions.c
php_string.h string.c


> I think it would be better to either use a correct algorithm or not to
> add this function at all. I think it's a reasonable expectation on a
> user's part to assume that foo_shuffle() actually does a proper
> shuffle. We got all sorts of complaints about the array shuffling code
> being broken.
>
> -adam
>



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to