php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24050 mt_rand() returns 1898087491 too often
Submitted: 2003-06-05 18:15 UTC Modified: 2003-08-02 14:43 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: ptchristendom at yahoo dot com Assigned:
Status: Closed Package: Math related
PHP Version: 4.3.3-dev OS: win32 only
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ptchristendom at yahoo dot com
New email:
PHP Version: OS:

 

 [2003-06-05 18:15 UTC] ptchristendom at yahoo dot com
The function mt_rand() has a "preference" for the value 1898087491 for a majority (but not all) of the default seedings.  As a result, if you don't seed it you will generate far too many collisions on the value 1898087491.  

If you seed it with values such as 0, 1, 2, 3, etc., the problem will not occur (these are all the seeds that I tried); however, the mt_rand should work properly when not seeded.  Further, there SHOULD NOT be any single seed that causes this value to occur more than others.   This leads me to believe that mt_rand() is not implemented correctly when not seeded.

Here it says that it is not necessary to use mt_srand() to obtain "random" data:
http://us3.php.net/manual/en/function.mt-srand.php

---------------------------------------------------------
The following shows a test script that reproduces the problem:

D:\php4-win32-STABLE-200306052030>type unseeded2.php

<? 
for ($i = 0; $i < 25; $i++) 
  print `php -q unseeded.php`."\n"; 
?>

D:\php4-win32-STABLE-200306052030>type unseeded.php

<?
        $j = 0;
        for ($i = 0; $i < 65536; $i++)
                if (mt_rand() == 1898087491) $j++;
        print $j;
?>

D:\php4-win32-STABLE-200306052030>php unseeded2.php
Content-type: text/html
X-Powered-By: PHP/4.3.3-dev

36480
39710
2308
41576
38524
39247
5005
5449
38011
29808
37577
5738
46785
42418
45619
42322
39296
15909
35019
39127
26830
37223
33348
22713
0

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-06 02:07 UTC] sniper@php.net
Can not reproduce within Linux, must be some windows only issue..

 [2003-08-02 14:43 UTC] iliaa@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.

This bug was related to a compilation problem on the shapshot box, which resulted in incorrect handling of floats.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Dec 06 03:03:58 2022 UTC