I am surprised that you get even 7 digits. Would padding just add spaces to the right? What happens if the rand function returns 1?
Perhaps you will get 7 and 8 digits just by pure chance - an accident. Try it for a while and you should start to see each combination between 1 and 8 digits.
This is plus what Bart said, lead 0 will just leave.
Speaking of which, if you have rand, why do you shuffle? Should be enough.
srand ((double) microtime( )*1000000); $maxid = rand(10000000,99999999); echo $maxid;
Test code (to illustrate the wrong logic)
srand ((double) microtime( )*1000000); for($i = 0; $i < 1000000; $i++) { $maxid = rand(0,100000000); if($maxid < 100000){ echo $maxid . "<br>"; $mtidno = str_pad($maxid,8); $shuffled = str_shuffle($mtidno); echo $shuffled . "<br>"; } } echo "done <br>";
See the following output for clear spaces after shuffling.
0 0 12207 20 21 7 82397 78 329 64086 64086 42724 4 4 2 27 21362 216 32 57983 7 3 598
source share