• PHP Video Tutorials

PHP - Stats Rand Gen Ibinomial Negative() Function



Definition and Usage

The stats_rand_gen_ibinomial_negative() function can generate random deviate from the negative binomial distribution.

Syntax

  int stats_rand_gen_ibinomial_negative( int $n, float $p )

Parameters

Sr.No Parameter Description
1

n

The number of success

2

p

The success rate

Return Values

The stats_rand_gen_ibinomial_negative() function can return a random deviate from the negative binomial distribution where the number of success is n, and the success rate is p.

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 deviate from the negative binomial distribution where the number of success is 2, and the success rate is 0.5.

<?php
   var_dump(is_int(stats_rand_ibinomial_negative(2, 0.5)));
?>

Output

This will produce following result −

bool(true)

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_negative(-1, 0.5));   // n < 0
?>

Output

This will produce following result and a warning in logs PHP Warning: stats_rand_ibinomial_negative(): n < 0. n : -1

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_negative(1, -0.1));   // pp < 0
?>

Output

This will produce following result and a warning in logs PHP Warning: stats_rand_ibinomial_negative(): p is out of range. p : -1E-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_negative(1, 1.1));    // pp > 1
?>

Output

This will produce following result and a warning in logs PHP Warning: stats_rand_ibinomial_negative(): p is out of range. p : 1E+0

bool(false)
Advertisements