Random num

I am trying to create a ID like a number which should be different each time I click a button. How do I make the number different or change to a random number each time I hit the button....?



Moiz
LVL 4
Moizsaif123Asked:
Who is Participating?
 
Jaime OlivaresSoftware ArchitectCommented:
A usual technique is to use md5/uniqid/rand combination:

$id = md5(uniqid(rand()));
0
 
minichickenCommented:
Hi

If you just want numbers, you can just use
rand([min], [max]);

if you want better random numbers you can use
mt_rand ( [int min, int max])

more info:
http://za2.php.net/rand
http://za2.php.net/mt_rand
0
 
TagorCommented:
rand(1,9) will create a random number between between 0 and 10.

You could use it this way: $number = "".rand(1,9)."".rand(1,9)."".rand(1,9)."".rand(1,9)."".rand(1,9)."";
This will create a random number that is 5 digits long.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.