php.net |  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
 [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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-11-10 14:54 UTC] hholzgra@php.net
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-2021 The PHP Group
All rights reserved.
Last updated: Sun Nov 28 03:03:14 2021 UTC