Keep track of random number generation with the number generator

Views: 12 Last modified: August 03rd, 2011 Comments: 0

Are you curious how “random” the (better) number generator is when it comes generating ? You can check generated number, times that x is between y and z, and the total times of refreshing the page with f5. This is just a test and just for curiosity.

<?php
# Session start
session_start();

# Seed the generator
mt_srand((double)microtime()*1000000);

# Random between min, max
$random = mt_rand(1,50);

# Set defaults
if (!isset($_SESSION['total'])):
    $_SESSION['between'] = 0;
    $_SESSION['total'] = 0;
endif;

# Keep track
if ($random > 20 && $random < 40)
{
    $_SESSION['between']++;
}
# Show results
echo '<br />Generated number: '. $random;
echo '<br />Between: '. $_SESSION['between'];
echo '<br />Total:'. ++$_SESSION['total'];
?>
VN:F [1.9.13_1145]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)
    Bluehost

    Mail this!

    To: From:Sum {0+9} =  
    Anything to add ?

        You must be logged in to post a comment.