Bug #2887: mt_rand(int min, int max) doesn't seem to use min and max

From: Date: Wed, 01 Dec 1999 20:39:13 +0000
Subject: Bug #2887: mt_rand(int min, int max) doesn't seem to use min and max
Groups: php.dev 
Request: Send a blank email to php-dev+get-13363@lists.php.net to get a copy of this message
From: mikeuser@hotmail.com Operating system: WinNT PHP version: 3.0.11 PHP Bug Type: Misbehaving function Bug description: mt_rand(int min, int max) doesn't seem to use min and max BUG! (WinNT)<BR> Setting min-max range doesn't work! I get values well beyond range. <PRE> echo "<B>mt_rand(0,20)=".mt_rand(0,20)."</B><BR>"; Actual results: mt_rand(0,20)=879286 mt_rand(0,20)=1357383 mt_rand(0,20)=286308 etc... </PRE> A work-around using the % operator: <PRE> $randnum = $mt_rand() % ($maxVal-$minVal) + minVal; </PRE>

« previous php.dev (#13363) next »