[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Random num

Posted on 2004-10-17
3
Medium Priority
?
277 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 160 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 120 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 120 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

649 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