#46587 [Opn->Asn]: mt_/rand produce out of range numbers when min = 0 and max > get_randmax

From: Date: Mon, 17 Nov 2008 06:36:19 +0000
Subject: #46587 [Opn->Asn]: mt_/rand produce out of range numbers when min = 0 and max > get_randmax
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-131013@lists.php.net to get a copy of this message
ID: 46587 Updated by: pajoye@php.net Reported By: atomo64 at gmail dot com -Status: Open +Status: Assigned Bug Type: *Math Functions Operating System: Debian sid PHP Version: 5.2.6 -Assigned To: +Assigned To: pajoye Previous Comments: ------------------------------------------------------------------------ [2008-11-17 02:50:20] atomo64 at gmail dot com Description: ------------ Whenever min is set to 0 and max is set to anything greater than getrandmax (or the mt_ version) the returned PRN is always (despite the upper limit check in the example code) a number minor than 0. Reproduce code: --------------- define("UL", mt_getrandmax()+1000); $r=mt_rand(0, UL); if ($r < 0 || $r > UL) echo "Random value out of range\n"; Expected result: ---------------- No output Actual result: -------------- Random value out of range ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=46587&edit=1

« previous php.bugs (#131013) next »