ShivaGupta Posted May 22, 2013 Share Posted May 22, 2013 how to generat random 10 digit numbers Quote Link to comment Share on other sites More sharing options...
Dathremar Posted May 22, 2013 Share Posted May 22, 2013 I don't know if this question deserves an answer, but just googling what you wrote here, got me this as a first response: http://elementdesignllc.com/2011/06/generate-random-10-digit-number-in-php/ So please don't be that lazy and try using google from time to time. Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 22, 2013 Share Posted May 22, 2013 It depends on what you mean by 10 digit. Do you consider 0000000001 the first valid number or is it 1000000000? Either way mt_rand() is what you want. mt_rand() $randNo = mt_ranf(1000000000, 9999999999); or $randNo = mt_ranf(1, 9999999999); Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted May 22, 2013 Solution Share Posted May 22, 2013 I cannot get mt_rand() to produce a number larger than 1,410,065,401 $max = 0; for ($i=0; $i<1000000; $i++) { $max = max($max, mt_rand(1000000001,9999999999)); } echo $max; //--> 1410065401 so you may need something like for ($i=0, $num=''; $i<10; $i++) { $num .= rand(1,9); } echo $num; Quote Link to comment 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.