lcg_value(): Combined linear congruential generator

echo lcg_value();
Out put is ( may change ) , refresh this page and check.
0.031457284391523
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
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com











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