7.50 Mathématiques
7 Index des fonctions
Manuel PHP
. Introduction . Pré-requis . Installation . Configuration à l'exécution . Types de ressources . Constantes prédefinies . abs . acos . acosh . asin . asinh . atan . atan2 . atanh . base_convert . bindec . ceil . cos . cosh . decbin . dechex . decoct . deg2rad . exp . expm1 . floor . fmod . getrandmax . hexdec . hypot . is_finite . is_infinite . is_nan . lcg_value . log . log10 . log1p . max . min . mt_getrandmax . mt_rand . mt_srand . octdec . pi . pow . rad2deg ->rand . round . sin . sinh . sqrt . srand . tan . tanh
|
7.50.47 rand()Génère une valeur aléatoire[ Exemples avec rand ] PHP 3, PHP 4
int
rand (
int
min
,
int
max
)
Appelée sans les options
min
et
max
,
rand
retourne un
nombre pseudo-aléatoire entre 0 et
RAND_MAX
.
Si vous voulez un nombre aléatoire entre 5 et 15
(inclus), par exemple, utilisez
rand (5, 15)
.
Note |
Depuis
PHP
4.2.0, il n'est plus besoin d'initialiser le générateur de nombres aléatoires avec
srand
ou
mt_srand
car c'est fait automatiquement.
|
Note |
Dans les versions antérieures à la 3.0.7 la signification
du paramètre
max
était longueur.
Pour avoir le même résultat, il faut utiliser
mt_rand (5, 11)
pour obtenir un nombre aléatoire
entre 5 et 15.
|
Voir aussi
srand
,
mt_rand
et
getrandmax
.
|