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).
<?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;
?>
<?php
$weight = 0.8; // Adjust weight to favor higher values
// Generate a weighted random value
$weightedRandom = lcg_value() * $weight;
echo "Weighted Random Value: " . $weightedRandom;
?>
<?php
function rollDice() {
return 1 + floor(lcg_value() * 6);
}
echo "You rolled a: " . rollDice();
?>
<?php
function randomColor() {
$brightness = 100 + (lcg_value() * 155); // Adjusts brightness between 100 and 255
return "rgb($brightness, $brightness, $brightness)";
}
echo "Random color: " . randomColor();
?>
<?php
function randomEvent($probability) {
return lcg_value() < $probability ? "Event occurs" : "Event does not occur";
}
echo randomEvent(0.3); // 30% chance of event occurring
?>
Author
🎥 Join me live on YouTubePassionate 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.