note 83360 added to function.mt-rand

From: Date: Thu, 22 May 2008 11:58:20 +0000
Subject: note 83360 added to function.mt-rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-139609@lists.php.net to get a copy of this message
I forgot to add a side-note to my post about the unique random number function. If the array count is more than half of the random number max, the function could take a very long time to process, maybe even go into an infinite loop. The best way to avoid this is to set the max at twice the array count; i.e. if you want an array of 10 unique random numbers, the maximum random number needs to be at least 20. For my purposes, I have 50 pictures to choose from, and the function randomly picks 20 of them to display on the webpage, without displaying an image twice. ---- Server IP: 64.71.164.2 Probable Submitter: 68.47.206.149 ---- Manual Page -- http://www.php.net/manual/en/function.mt-rand.php Edit -- https://master.php.net/note/edit/83360 Del: integrated -- https://master.php.net/note/delete/83360/integrated Del: useless -- https://master.php.net/note/delete/83360/useless Del: bad code -- https://master.php.net/note/delete/83360/bad+code Del: spam -- https://master.php.net/note/delete/83360/spam Del: non-english -- https://master.php.net/note/delete/83360/non-english Del: in docs -- https://master.php.net/note/delete/83360/in+docs Del: other reasons-- https://master.php.net/note/delete/83360 Reject -- https://master.php.net/note/reject/83360 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139609) next »