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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
14 - 10 = ?
Subscribe to this entry?

 
 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 06 15:01:28 2024 UTC