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:

<?php
echo lcg_value();
?>

Sample output:

0.508212039328
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Backendpseudo-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

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.