|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #66718 Please add Mersenne Twister versions of shuffle and array_rand
Submitted: 2014-02-15 01:09 UTC Modified: 2016-09-09 02:44 UTC
Avg. Score:3.5 ± 1.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: php at barrayar dot org Assigned: yohgaki (profile)
Status: Closed Package: SPL related
PHP Version: Irrelevant OS: Any
Private report: No CVE-ID: None
 [2014-02-15 01:09 UTC] php at barrayar dot org
It would be very helpful if PHP had native Mersenne Twister equivalents for all the various random functions, e.g. mt_shuffle, mt_array_rand.  (I'm not sure if there's any others that would be relevant.)  The MT RNG is superior to the regular srand/rand functions in all respects except this one.  While it's not that hard to implement mt_shuffle and mt_array_rand equivalents in PHP, they would be faster and more standardized if they were native.

(On a related note, it would also be helpful if PHP had a native class for creating separate RNG pools, since sometimes you want to be able to recreate a random sequence from a given seed, but since all mt_rand calls use the same RNG pool, you can't have two concurrent RNG pools.)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-07-15 12:06 UTC]
-Status: Open +Status: Verified
 [2014-07-15 12:06 UTC]
We may simply use php_mt_rand()
 [2014-07-16 06:22 UTC]
-Assigned To: +Assigned To: yohgaki
 [2015-08-05 12:18 UTC]
Using php_mt_rand() for array_rand() seems to be reasonable
anyway, to resolve bug #45301.
 [2016-09-09 02:44 UTC]
-Status: Verified +Status: Closed
 [2016-09-09 02:44 UTC]
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Mar 30 01:03:40 2023 UTC