PHP - Stats Rand Gen Ibinomial() Function
Definition and Usage
The stats_rand_gen_ibinomial() function generates a single random deviate from a binomial distribution whose number of trials is "n" (n >= 0) and whose probability of an event in each trial is "pp" ([0;1]).
Syntax
int stats_rand_gen_ibinomial( int $n, float $pp )
Parameters
| Sr.No | Parameter | Description |
|---|---|---|
| 1 | n |
The number of trials |
| 2 | pp |
The probability of an event in each trial |
Return Values
The stats_rand_gen_ibinomial() function can return a random deviate from the binomial distribution whose number of trials is n, and whose probability of an event in each trial is pp.
Dependencies
This function was first introduced in statistics extension (PHP 4.0.0 and PEAR 1.4.0). We have used latest release of stats-2.0.3 (PHP 7.0.0 or newer and PEAR 1.4.0 or newer) for this tutorial
Example
In the following example, we compute random deviatition from the binomial distribution whose number of trials is 0, and whose probability of an event in each trial is 0.7.
<?php var_dump(stats_rand_ibinomial(0, 0.7)); ?>
Output
This will produce following result −
int(0)
Example
In the following example, we compute random deviatition from the binomial distribution whose number of trials is 3, and whose probability of an event in each trial is 0.
<?php var_dump(stats_rand_ibinomial(3, 0)); ?>
Output
This will produce following result −
int(0)
Example
In the following example, we compute random deviatition from the binomial distribution whose number of trials is 3, and whose probability of an event in each trial is 1.
<?php var_dump(stats_rand_ibinomial(3, 1)); ?>
Output
This will produce following result −
int(3)
Example
Following is an error case. In the following example, we pass n < 0. A warning is displayed in logs.
<?php // error cases var_dump(stats_rand_ibinomial(-1, 0.7)); // n < 0 ?>
This will produce following result and a warning in logs PHP Warning: stats_rand_ibinomial(): Bad values for the arguments. n : -1 pp : 7.000000E-1vs
bool(false)
Example
Following is an error case. In the following example, we pass pp < 0. A warning is displayed in logs.
<?php // error cases var_dump(stats_rand_ibinomial(3, -0.1)); // pp < 0 ?>
Output
This will produce following result and a warning in logs PHP Warning: stats_rand_ibinomial(): Bad values for the arguments. n : 3 pp : -1.000000E-1
bool(false)
Example
Following is an error case. In the following example, we pass pp > 1. A warning is displayed in logs.
<?php // error cases var_dump(stats_rand_ibinomial(3, 1.1)); // pp > 1 ?>
Output
This will produce following result and a warning in logs PHP Warning: stats_rand_ibinomial(): Bad values for the arguments. n : 3 pp : 1.100000E+0
bool(false)