note 106270 added to function.array-rand
| From: | shayfalador at gmail dot com | Date: | Sun, 23 Oct 2011 22:04:29 +0000 |
| Subject: | note 106270 added to function.array-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-184084@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 69.147.83.197
Probable Submitter: 84.229.10.246
----
Manual Page -- http://www.php.net/manual/en/function.array-rand.php
Edit -- https://master.php.net/note/edit/106270
Del: integrated -- https://master.php.net/note/delete/106270/integrated
Del: useless -- https://master.php.net/note/delete/106270/useless
Del: bad code -- https://master.php.net/note/delete/106270/bad+code
Del: spam -- https://master.php.net/note/delete/106270/spam
Del: non-english -- https://master.php.net/note/delete/106270/non-english
Del: in docs -- https://master.php.net/note/delete/106270/in+docs
Del: other reasons-- https://master.php.net/note/delete/106270
Reject -- https://master.php.net/note/reject/106270
Search -- https://master.php.net/manage/user-notes.php