note 109247 added to function.array-rand
| From: | tim at ramasaig dot com | Date: | Fri, 29 Jun 2012 11:31:06 +0000 |
| Subject: | note 109247 added to function.array-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-188967@lists.php.net to get a copy of this message | ||
Following up Sebmil's comment of August 2011:
I've tried running Sebmil's test script on my computer, and for me the same half-dozen or
so keys always appear at the top of the printed list (and the order below that doesn't change
much). if I've understood it correctly, that must mean that there is considerable bias in the
'random' selection ?
The least selected key is always 23, followed by 26, 21, 32, 24, 4. After that there's a small
amount of variation each time the script is run, but 37 always seems to be at the bottom (most
selected). Actual values change a bit, but typically 23 => 2120 and 37 => 2790.
Sebmil's script is selecting 10 out of 40 keys, and the results may change if fewer (or more)
keys are selected. That's what I'll look at next.
For many purposes (random selection of images for display on a web site, say), this anomaly may not
matter much, but I can see there would be instances where it was important.
----
Server IP: 69.147.83.197
Probable Submitter: 80.229.172.129
----
Manual Page -- http://www.php.net/manual/en/function.array-rand.php
Edit -- https://master.php.net/note/edit/109247
Del: integrated -- https://master.php.net/note/delete/109247/integrated
Del: useless -- https://master.php.net/note/delete/109247/useless
Del: bad code -- https://master.php.net/note/delete/109247/bad+code
Del: spam -- https://master.php.net/note/delete/109247/spam
Del: non-english -- https://master.php.net/note/delete/109247/non-english
Del: in docs -- https://master.php.net/note/delete/109247/in+docs
Del: other reasons-- https://master.php.net/note/delete/109247
Reject -- https://master.php.net/note/reject/109247
Search -- https://master.php.net/manage/user-notes.php