8.65 Mathématiques
8 Référence des fonctions
Manuel PHP
. Introduction . Pré-requis . Installation . Configuration à l'exécution . Types de ressources . Constantes pré-définies . 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
|
8.65.52 srand()Initialise le générateur de nombres aléatoires[ Exemples avec srand ] PHP 3, PHP 4, PHP 5
void
srand (
int
seed
)
srand
initialise le générateur de
nombres aléatoires avec
seed
.
Depuis PHP 4.2.0, le paramètre
seed
est
devenu optionnel et est généré par PHP s'il n'est
pas renseigné.
| Exemple avec srand |
<?php // initialise avec les microsecondes function make_seed() { list($usec, $sec) = explode(' ', microtime()); return (float) $sec + ((float) $usec * 100000); } srand(make_seed()); $randval = rand(); ?>
|
| Note | |
Depuis
PHP
4.2.0,
vous n'avez plus besoin d'initialiser le générateur de nombres aléatoires
avec
srand
ou
mt_srand
car c'est
fait automatiquement.
|
Voir aussi
rand
,
getrandmax
et
mt_srand
.
|