PHP Bugs  
php.net | support | documentation | report a bug | advanced search | search howto | statistics | login

go to bug id or search bugs for  

Bug #7281 rand() gives range warnings over 15 bits
Submitted:17 Oct 2000 11:26am UTC Modified: 10 Nov 2000 2:54pm UTC
From:a dot schommer at dialogmedien dot de Assigned to:
Status:Closed Category:Math related
Version:4.0.2 OS:Solaris 2.7
View/Vote Developer Edit Submission

[17 Oct 2000 11:26am 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.
[10 Nov 2000 2:54pm 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 

RSS feed | show source 

PHP Copyright © 2001-2009 The PHP Group
All rights reserved.
Last updated: Sat Nov 21 10:30:49 2009 UTC