gmp_random_bits

(PHP 5 >= 5.6.3, PHP 7, PHP 8)

gmp_random_bitsGénère un nombre aléatoire

Description

gmp_random_bits(int $bits): GMP

Génère un nombre aléatoire. Le nombre sera dans l'intervalle 0 et (2 ** bits) - 1.

Le paramètre bits doit être plus grand que 0, et la valeur maximale sera restreinte par la mémoire disponible.

Liste de paramètres

bits

Le nombre d'octets.

Valeurs de retour

Un nombre GMP aléatoire.

Exemples

Exemple #1 Exemple avec gmp_random_bits()

<?php
$rand1 
gmp_random_bits(3); // nombre aléatoire entre 0 et 7
$rand2 gmp_random_bits(5); // nombre aléatoire entre 0 et 31

echo gmp_strval($rand1) . "\n";
echo 
gmp_strval($rand2) . "\n";
?>

L'exemple ci-dessus va afficher :

3
15

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top