ShivaGupta Posted May 22, 2013 Share Posted May 22, 2013 how to generat random 10 digit numbers Link to comment https://forums.phpfreaks.com/topic/278295-how-to-generat-random-10-digit-numbers/ 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. Link to comment https://forums.phpfreaks.com/topic/278295-how-to-generat-random-10-digit-numbers/#findComment-1431705 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); Link to comment https://forums.phpfreaks.com/topic/278295-how-to-generat-random-10-digit-numbers/#findComment-1431709 Share on other sites More sharing options...
Barand Posted May 22, 2013 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; Link to comment https://forums.phpfreaks.com/topic/278295-how-to-generat-random-10-digit-numbers/#findComment-1431712 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.