[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 280
  • Last Modified:

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
0
Moizsaif123
Asked:
Moizsaif123
3 Solutions
 
Jaime OlivaresCommented:
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now