|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-01-21 19:06 UTC] callawey at gmail dot com
Description: ------------ rand and mt_rand generates random lenght integer between -9999999999 and +9999999999. example mt_rand(100000000000, 999999999999); outputs: -564, -688852, 5586666988, -68889558 Reproduce code: --------------- $str = mt_rand(100000000000, 999999999999); Expected result: ---------------- positive numbers between 100000000000 and 999999999999 Actual result: -------------- -492911349,1162038978,-219333642 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 14:00:01 2025 UTC |
while($row = $DB->fetchArray($result)) { for($i=0;$i<=12;$i++) { $str .= rand(0,9); } //$str = mt_rand(100000000000, 999999999999); $sqlc = sprintf("UPDATE %s SET user_id='%s' WHERE id='%s'", $DB->prefix("users"), $str, $row["id"]); $DB->queryF($sqlc); } this code makes all colums -1while($row = $DB->fetchArray($result)) { $str = ""; for($i=0;$i<=12;$i++) { $str .= rand(0,9); } $sqlc = sprintf("UPDATE %s SET user_id='%s' WHERE id='%s'", $DB->prefix("users"), $str, $row["id"]); $DB->queryF($sqlc); } this returns same number everytime even i use $str = ""; in every loop Why ?