phpretard Posted May 6, 2008 Share Posted May 6, 2008 I would like to consistanly generate a 6 digit random number. Seems easy enough, but the code below sometimes generates less than or 6 digits? rand(000000, 999999); Anybody know why? Link to comment https://forums.phpfreaks.com/topic/104419-solved-generate-random-number/ Share on other sites More sharing options...
Daniel0 Posted May 6, 2008 Share Posted May 6, 2008 str_pad(rand(0, 999999), '0', STR_PAD_LEFT); or sprintf('%06d', rand(0, 999999)); Also, if an integer starts with 0 in PHP then it will be considered octal, so you might get odd results if you start doing that. Link to comment https://forums.phpfreaks.com/topic/104419-solved-generate-random-number/#findComment-534544 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.