|  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: anakin at php dot pl
New email:
PHP Version: OS:


 [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: Tue Jun 06 02:03:40 2023 UTC