Recherche sur les Noms des fonctions php/mysql
srand()
Définition
Initialise le générateur de nombres aléatoires - (PHP 4, PHP 5)Description
void srand
([ int $seed
] )
Initialise le générateur de nombres aléatoires avec seed , ou avec une valeur aléatoire si aucun paramètre seed n'est fourni.
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.
Liste de paramètres
- seed
-
valeur d'initialisation optionnelle
Historique
| Version | Description |
|---|---|
| Depuis la version 4.2.0 | Le paramètre seed est devenu optionnel et vaut, par défaut, une valeur aléatoire si omis. |
Exemples
Exemple #1 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();
?>
Bouts de code utilisant la fonction srand()
<?php /* ... */
$emailNOSPAMaddy = '';
srand ((float) microtime() * 1000000);
for ($i = 0; $i < strlen($this->emailaddy); $i = $i + 1) {
/* ... */ ?>
<?php /* ... */
$chaine = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
srand((double)microtime()*1000000);
for($i=0; $i<$ct; $i++) {
/* ... */ ?>
<?php /* ... */
function encrypt($txt){
srand((double)microtime()*1000000);
$encrypt_key = md5(rand(0,32000));
/* ... */ ?>
<?php /* ... */
$chaine ="mnoTUzS5678kVvwxy9WXYZRNCDEFrslq41GtuaHIJKpOPQA23LcdefghiBMbj0";
srand((double)microtime()*1000000);
for($i=0; $i<8; $i++){
/* ... */ ?>
<?php /* ... */
// On choisit une combinaison ici.
srand((double)microtime()*1000000);
for($i=; $i<$nombreDeCaracteres; $i++){
/* ... */ ?>
Connexion
Les fonctions
Références
- abs
- acos
- acosh
- asin
- asinh
- atan2
- atan
- 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
- log10
- log1p
- log
- max
- min
- mt_getrandmax
- mt_rand
- mt_srand
- octdec
- pi
- pow
- rad2deg
- rand
- round
- sin
- sinh
- sqrt
- srand
- tan
- tanh





