Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I generate a random number between 10000000 and 99999999?

Status
Not open for further replies.

Sina

Technical User
Jan 2, 2001
309
CA
Hello everyone,

I need help to generate a random number between 10000000 and 99999999?

When I use rand i do get an error (warning out of range).

Thank you all
 
Have you tried running the getrandmax() function to see what the largest possible random number on the system is?

Tip: for quick documentation on any PHP function, just do this kind of thing:
You might also want to try the new PHP-specific random function called mt_rand(): -------------------------------------------

"Calculus is just the meaningless manipulation of higher symbols"
                          -unknown F student
 
if you really need to do random numbers with a lot of characters ....
just do a loop it's slow, but it works
exemple in your case :
$value=strval(rand(1,9)); //because you need 1 and not 0 for the first
for ($i=0;$i<7;$i++) $value.=strval(rand(0,9));

echo $value;
this way you can even get numbers with 100 char, they just become strings ...

not the best way to do it, but better than nothing Khaldryck
Programmer at the University of Brussel (Belgium)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top