|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28305 range problem
Submitted: 2004-05-06 19:44 UTC Modified: 2004-05-06 20:14 UTC
From: anakin at php dot pl Assigned:
Status: Not a bug Package: Math related
PHP Version: 4.3.4 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
40 - 24 = ?
Subscribe to this entry?

 [2004-05-06 19:44 UTC] anakin at php dot pl
Using array_rand wirh range function produces incorrect results.

Reproduce code:
 print_r(array_rand(range(1, 6), 6));

Expected result:
An array with numbers from 1 to 6 shuffled.

Actual result:
For example:
Array ( [0] => 4 [1] => 2 [2] => 3 [3] => 1 [4] => 0 [5] => 5 ) 
See key '4'. 0 (zero) does not match range(1, 6).


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-05-06 20:14 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

From the manual:

If you are picking only one entry, array_rand() returns the key for a random entry. Otherwise, it returns an array of keys for the random entries. This is done so that you can pick random keys as well as values out of the array. 

Your "actual results" are what you should expect, arrray KEYS 0 through 5.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Jun 09 12:03:39 2023 UTC