PHP - Stats Rand Ranf() Function
Definition and Usage
The stats_rand_ranf() function can generate a random floating-point number between 0 and 1.
Syntax
float stats_rand_ranf( void )
Return Values
The stats_rand_ranf() function can return a random floating point number from a uniform distribution between 0 (exclusive) and 1 (exclusive).
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 generate a random floating point number and check if its float and ranges between 0 and 1.
<?php $r = stats_rand_ranf(); var_dump(is_float($r)); var_dump(0 <= $r && $r < 1); ?>
Output
This will produce following result −
bool(true) bool(true)
Advertisements