note 41282 deleted from function.shuffle by aidan

From: Date: Thu, 26 Aug 2004 22:32:45 +0000
Subject: note 41282 deleted from function.shuffle by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-75363@lists.php.net to get a copy of this message
Note Submitter: fdellutri at tiscali dot it ---- Dear chvickers, thanks for idea, but the function mix works as an O(n^3), where n is the $org_arr size. The follow replacement works as an O(n). function mix($org_arr) { $keys = array_keys($org_arr); $max = count($org_arr); $new_arr = array(); while (count($new_arr) < $max) { $r = rand(0,count($keys)-1); $new_arr[$keys[$r]] = $org_arr[$keys[$r]]; unset($keys[$r]); $keys = array_values($keys); } return $new_arr; }

« previous php.notes (#75363) next »