ballhogjoni Posted January 8, 2009 Share Posted January 8, 2009 I want to create a random number that is 10 digits long. I was looking at rand but that doesn't give me exactly what I want. How do you do that? Link to comment https://forums.phpfreaks.com/topic/140032-solved-create-a-random-number-at-a-certain-length/ Share on other sites More sharing options...
.josh Posted January 8, 2009 Share Posted January 8, 2009 for ($x = 0; $x < 10; $x++) { $string .= rand(0,9); } Link to comment https://forums.phpfreaks.com/topic/140032-solved-create-a-random-number-at-a-certain-length/#findComment-732627 Share on other sites More sharing options...
kenrbnsn Posted January 8, 2009 Share Posted January 8, 2009 What's wrong with: <?php $str = rand(1000000000,9999999999); echo $str; ?> Ken Link to comment https://forums.phpfreaks.com/topic/140032-solved-create-a-random-number-at-a-certain-length/#findComment-732742 Share on other sites More sharing options...
.josh Posted January 8, 2009 Share Posted January 8, 2009 What's wrong with: <?php $str = rand(1000000000,9999999999); echo $str; ?> Ken Because more than likely the highest number rand() can return is 2,147,483,647 since it generates an integer. can do echo getrandmax(); to see what the highest number rand() will generate on your system. Link to comment https://forums.phpfreaks.com/topic/140032-solved-create-a-random-number-at-a-certain-length/#findComment-732905 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.