Solved

Random num

Posted on 2004-10-17
3
246 Views
Last Modified: 2006-11-17
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
Comment
Question by:Moizsaif123
3 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 40 total points
ID: 12334470
A usual technique is to use md5/uniqid/rand combination:

$id = md5(uniqid(rand()));
0
 
LVL 12

Assisted Solution

by:minichicken
minichicken earned 30 total points
ID: 12334514
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
 
LVL 4

Assisted Solution

by:Tagor
Tagor earned 30 total points
ID: 12334648
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now