Backend Development 1 min read

PHP lcg_value() Function – Combined Linear Congruential Generator

The article explains PHP’s lcg_value() function, which generates a pseudo‑random float between 0 and 1 by combining two linear congruential generators with periods 2^31‑85 and 2^31‑249, describes its return value, provides a PHP code example, and shows a sample output.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP lcg_value() Function – Combined Linear Congruential Generator

The PHP function lcg_value() returns a pseudo‑random floating‑point number in the range (0, 1). It combines two linear congruential generators whose periods are 2^31 − 85 and 2^31 − 249, giving a total period equal to the product of these two prime numbers.

Return value: a pseudo‑random number between 0 and 1.

Example:

Sample output:

0.508212039328
BackendphpPseudo‑randomlinear congruential generatorlcg_value
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.