PHP mt_rand() Functie
Voorbeeld
Genereer willekeurige getallen:
<?php
echo(mt_rand() . "<br>");
echo(mt_rand() . "<br>");
echo(mt_rand(10,100));
?>
Definitie en gebruik
De functie mt_rand() genereert een willekeurig geheel getal met behulp van het Mersenne Twister-algoritme.
Voorbeeldtip: Als u een willekeurig geheel getal tussen 10 en 100 (inclusief) wilt, gebruikt u mt_rand (10.100).
Syntaxis
mt_rand();
or
mt_rand(min,max);
Parameterwaarden
Parameter | Description |
---|---|
min | Optional. Specifies the lowest number to return. Default is 0 |
max | Optional. Specifies the highest number to return. Default is mt_getrandmax() |
Technische details
Winstwaarde: | Een willekeurig geheel getal tussen min (of 0) en max (of mt_getrandmax() inclusief). Retourneert ONWAAR als max < min |
---|---|
Retourtype: | Geheel getal |
PHP-versie: | 4+ |
PHP-wijzigingslogboek: | PHP 7.1: rand() is een alias van mt_rand() PHP 5.3.4: Geeft een E_WARNING en geeft FALSE terug als max < min . PHP 4.2.0: Random number generator wordt automatisch gezaaid. |
❮ PHP-wiskundereferentie