php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1166 rand() max value is always 1 greater than it should be.
Submitted: 1999-02-19 22:18 UTC Modified: 1999-02-27 09:31 UTC
From: mike24 at bellsouth dot net Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.6 OS: Redhat 5.1 Linux 2.0.35
Private report: No CVE-ID: None
 [1999-02-19 22:18 UTC] mike24 at bellsouth dot net
rand() always uses a max value 1 greater than inputed.

Consider the following code snippet:

<?php 
    srand((double)microtime()*1000000);
    $number = rand(5, 15);
    $echo "$number\n";
?>

$number should contain an integer between 5 and 15. However, this bug causes $number to contain an integer between 5 and 16.    

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-02-27 09:31 UTC] sas
This was fixed by Rasmus (I believe)

revision 1.35
date: 1999/02/15 06:04:11;  author: rasmus;  state: Exp;  lines: +18 -10
A slight tweak
----------------------------
revision 1.34
date: 1999/02/15 04:04:48;  author: rasmus;  state: Exp;  lines: +23 -6
Fix the broken rand() and mt_rand() ranges

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 12 06:01:31 2024 UTC