NOVINKA: Najžiadanejšie rekvalifikačné kurzy teraz s 50% zľavou + kurz AI ZADARMO. Nečakaj, táto ponuka dlho nevydrží! Zisti viac:

PHP - mt_rand

Trieda

Koreň \ Bez triedy

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

  • function mt_rand (int $min, int $max) : int
  • function mt_rand (int $min, int $max) : int

Parametre

NázovDátový typPredvolená hodnotaPopis
$minint 0

The lowest value that can be generated (inclusive).

$maxint 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

      Aktivity