How to make a random in php

Learn how to generate random numbers in PHP with this easy example!

Random Numbers with PHP

Using the rand() function, it's easy to generate random numbers with PHP. The rand() function can be used to generate a pseudo-random integer, with an optional minimum and maximum value. The syntax for the rand() function looks like this:


$number = rand(min, max);

The function returns a random number that is greater than or equal to min and less than or equal to max. For example, if you wanted to generate a random number between one and ten, you would use the following code:


$number = rand(1, 10);

This code would assign a random number between one and ten to the $number variable. If you wanted to generate a random number between zero and one hundred, you would use the following code:


$number = rand(0, 100);

The rand() function is a great way to generate random numbers in PHP. It's simple and easy to use, and it can be used to generate pseudo-random numbers of any size. If you need to generate random numbers in your application, the rand() function is a great place to start.

Answers (0)