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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
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.

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: Thu Dec 26 10:01:29 2024 UTC