|  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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
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-2024 The PHP Group
All rights reserved.
Last updated: Thu Feb 29 13:01:32 2024 UTC