• PHP Video Tutorials

PHP - Stats Rand Gen Exponential() Function



Definition and Usage

The stats_rand_gen_exponential() function can generate a random deviate from the exponential distribution.

Syntax

  float stats_rand_gen_exponential( float $av )

Parameters

Sr.No Parameter Description
1

av

The scale parameter

Return Values

The stats_rand_gen_exponential() function can return a random deviate from the exponential distribution of which the scale is av.

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 deviation from the exponential distribution.

<?php
   var_dump(is_float(stats_rand_gen_exponential(2)));
?>

Output

This will produce following result −

bool(true)

Example

In the following example, we compute random deviation from the exponential distribution by passing 0 as scae paramater.

<?php
   var_dump(stats_rand_gen_exponential(0));
?>

Output

This will produce following result −

float(0)

Example

Following is an error case. In the following example, we pass av < 0. A warning is displayed in logs.

<?php
   // error cases
   var_dump(stats_rand_gen_exponential(-0.1)); // av < 0
?>

Output

This will produce following result and a warning in logs PHP Warning: stats_rand_gen_exponential(): av < 0.0

bool(false)
Advertisements