|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7281 rand() gives range warnings over 15 bits
Submitted: 2000-10-17 11:26 UTC Modified: 2000-11-10 14:54 UTC
From: a dot schommer at dialogmedien dot de Assigned:
Status: Closed Package: Math related
PHP Version: 4.0.2 OS: Solaris 2.7
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: a dot schommer at dialogmedien dot de
New email:
PHP Version: OS:


 [2000-10-17 11:26 UTC] a dot schommer at dialogmedien dot de
rand() should work on int, which is about 2 billion. But i get
Warning: rand(): Invalid range: 1000000..1032768 in /tmp/apa2/htdocs/admin/tst.php3 on line 1

For this code:
<? print rand (1000000, 1032768); ?>
(a result is given anyway)

Not the size, but the difference seems to matter: If it exceeds 2^15-1, the warning comes up:
<? print rand (1000000, 1032767); ?>
produces only a result

sizeof(int) really is 4.
So i don't think it's my fault.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2000-11-10 14:54 UTC]
this is system dependant , on Solaris 2.7 you have

./stdlib.h:#define      RAND_MAX        32767

so that's it

you can always use the PHP function getrandmax() 
to find out the max. difference between the min and max
parameters for your system 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 18 20:01:28 2024 UTC