echo lcg_value();
Out put is ( may change ) , refresh this page and check.
0.32484231703631
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 & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.