PHP Questions Home | Register | Login
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website
Unanswered

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

How do I generate a random number?


There are various ways to generate a random number.

The simplest way and a method that will suffice for most uses is to use the rand function, which does not need to be seeded in recent versions of PHP.

It is standardly passed the min and max values you want to get a number between, for instance:

<?php
$random 
rand(1,100); echo "$random";
?>


This will print a number between 1 and 100 to the screen.



Comment on this Question and Answer >>>

ASK A QUESTION

More numbers PHP Questions

How do I format a number with commas like a monetary value?

How do I round down a number?

How do I work out the remainder of a division?

How do I round up a number?

How do I force a value to be treated as a number?



Custom Search