PHP - rand
Trieda
Metóda - rand
(PHP 4, PHP 5, PHP 7)
The rand() function returns a pseudo-random number.
The function can be called without parameters, so it returns a value between
0 and getrandmax(). However, you can not enter only one
parameter.
Procedurálne
Parametre
| Názov | Dátový typ | Predvolená hodnota | Popis |
|---|---|---|---|
| $min | int | The minimum value. | |
| $max | int | The maximum value. |
Mávratovej hodnoty
Vracia: int
A random number.
Príklady
<?php
echo ("a number between 0 and ". getrandmax()." = " . rand() . "<br />");
echo ("a number between 0 and ". getrandmax()." = " . rand(0, getrandmax()) . "<br />");
echo ("a number between -10 and -5 = " . rand(-10, -5) . "<br />"); // negative numbers work as well
echo ("a number between 10 and 10 = " . rand(10, 10) . "<br />"); // two identical numbers
echo ("a number between 20 and 10 = " . rand(20, 10) . "<br />"); // the order of the larger and smaller number does not matter
echo ("a number between 8.4 and 11.5 = " . rand(8.4, 11.5) . "<br />"); // decimal numbers generate integers
Súvisiace manuály
- function mt_rand (int $min, int $max) : int
- function random_bytes (int $length) : string
- function random_int () : int
