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? Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/104419-solved-generate-random-number/#findComment-534544 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.