lcg_value(): Combined linear congruential generator

echo lcg_value();
Out put is ( may change ) , refresh this page and check.
0.52970327064627
Syntax
flot lcg_value ( void)
The output is pseudo random number in the range of (0, 1).

Example 1: Generating a Range of Random Values Using lcg_value()

<?php
$min = 10;
$max = 100;

// Generate a random number between 10 and 100
$randomValue = $min + (lcg_value() * ($max - $min));

echo "Random value between 10 and 100: " . $randomValue;
?>

Example 2: Using lcg_value() for Weighted Randomness

<?php
$weight = 0.8; // Adjust weight to favor higher values

// Generate a weighted random value
$weightedRandom = lcg_value() * $weight;
echo "Weighted Random Value: " . $weightedRandom;
?>

Example 3: Simulating Dice Rolls with lcg_value()

<?php
function rollDice() {
    return 1 + floor(lcg_value() * 6);
}

echo "You rolled a: " . rollDice();
?>

Example 4: Randomizing Color Brightness with lcg_value()

<?php
function randomColor() {
    $brightness = 100 + (lcg_value() * 155); // Adjusts brightness between 100 and 255
    return "rgb($brightness, $brightness, $brightness)";
}

echo "Random color: " . randomColor();
?>

Example 5: Generating a Random Probability for Events

<?php
function randomEvent($probability) {
    return lcg_value() < $probability ? "Event occurs" : "Event does not occur";
}

echo randomEvent(0.3); // 30% chance of event occurring
?>

Math Functions base_convert(): Convert number From any base to other
decbin() Binary equivalent of decimal number
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer