PHP - mt_rand
Trieda
Metóda - mt_rand
(PHP 4, PHP 5, PHP 7)
Generates pseudo-random numbers using "Mersenne Twister":https://en.wikipedia.org/…enne_Twister method.
Warning: This function does NOT generate
cryptographically secure random numbers! If you need to use random-generated
numbers for cryptographic operations, use random_int(),
random_bytes() or openssl_random_pseudo_bytes()
instead!
If the interval between $max and $min is larger
than mt_randmax() (max - min > mt_randmax()),
the generator may return poorer random numbers than expected.
The number generating interval is inclusive.
Procedurálne
Parametre
| Názov | Dátový typ | Predvolená hodnota | Popis |
|---|---|---|---|
| $min | int | 0 | The lowest value that can be generated (inclusive). |
| $max | int | mt_randmax() | The highest value that can be generated (inclusive). |
Mávratovej hodnoty
Vracia: int
A pseudo-random integer between $min and $max. If
$min is greater than $max, false is
returned.
Príklady
Getting a random number between 0 and 100:
<?php
echo mt_rand (0, 100);
?>
Súvisiace manuály
- function rand (int $min, int $max) : int
- function random_bytes (int $length) : string
- function random_int () : int
