PHP lcg_value() Function


Definition and Usage

The lcg_value() function generates a random number between 0 and 1.

LCG stands for linear congruential generator. This generator generates a sequence of pseudo-randomized numbers calculated with a discontinuous piecewise linear equation. This is one of the oldest pseudorandom number generator algorithms

Syntax

lcg_value ( void ) : float

Parameters

Return Values

PHP lcg_value() function returns a pseudo random float value between 0.0 and 1.0, inclusive.

PHP Version

This function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.

Example

 Live Demo

Following is the example use of lcg_value() function −

<?php
   echo "lcg_value() = " . lcg_value() . "
";    echo "lcg_value() = " . lcg_value(); ?>

Output

This may produce following result −

lcg_value() = 0.45920201711279
lcg_value() = 0.18118693614628

Updated on: 29-Jun-2020

73 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements