note 106270 deleted from function.array-rand by danbrown

From: Date: Mon, 24 Oct 2011 16:06:05 +0000
Subject: note 106270 deleted from function.array-rand by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-184105@lists.php.net to get a copy of this message
Note Submitter: shayfalador at gmail dot com ---- Please note that when $num_req is constant and $num_req << count($input), this function is O(count($input)), which is not really cool. In this cases you can implement your own function, that takes one random key each time and puts in the new array, each time make sure that the key wasn't picked earlier. Using PHP arrays when $num_req << count($input) it is O($num_req^2). We can achieve O($num_req log($num_req)) using self balancing trees, but for practical PHP applications that would be an overkill and probably give even worse results. @Sebmil seems to be just fine on PHP 5.3.5 on windows 7 64-bit.

« previous php.notes (#184105) next »