Question #3799   Proposée par Answiki le 03/12/2021 à 12:34:36 UTC

Comment tirer nombre binaire aléatoire en PHP ?

Answer   Submitted by Answiki on 12/03/2021 at 12:35:34 PM UTC

Le code PHP suivant permet de tirer un nombre aléatoire entre 0 et 1 (booléen) :

$bool = rand(0,1);


Il est possible d'utiliser le résultat pour choisir au hasard entre deux actions :

if (rand(0, 1))
{ 
	// Action 1
}
else
{
	// Action 2
}


5 events in history
Answer by Answiki on 12/03/2021 at 12:35:34 PM

Le code PHP suivant permet de tirer un nombre aléatoire entre 0 et 1 (booléen) :

$bool = rand(0,1);


Il est possible d'utiliser le résultat pour choisir au hasard entre deux actions :

if (rand(0, 1))
{ 
	// Action 1
}
else
{
	// Action 2
}


Question by Answiki 12/03/2021 at 12:34:36 PM
Comment tirer nombre aléatoire entre 0 et 1 en PHP ?
Question by Answiki 12/03/2021 at 12:34:36 PM
Comment tirer nombre binaire aléatoire en PHP ?
Question by Answiki 12/03/2021 at 12:34:36 PM
Comment tirer un booléen au hasard en PHP ?
Question by Answiki 12/03/2021 at 12:34:36 PM
En PHP, comment choisir au hasard entre deux actions ?
# ID Query URL Count

Icons proudly provided by Friconix.