PHP rand() Function – Generating Random Integers

The PHP rand() function returns a pseudo‑random integer within a given range, defaulting to 0 through getrandmax() when no parameters are supplied, and includes details on its parameters, return value, and usage examples.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP rand() Function – Generating Random Integers

The PHP rand() function returns a pseudo‑random integer between a specified minimum and maximum, or between 0 and getrandmax() when no arguments are given.

Parameters

min – The lowest value to return (default 0).

max – The highest value to return (default getrandmax()).

Return value

A pseudo‑random integer between min (or 0) and max.

Example

<?php
echo rand();
"
"; // 7771
echo rand();
"
"; // 22264
echo rand(5,15);
"
"; // 11
?>
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendPHPfunctionrandomrand
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.