Source of kr_prng.php

<?php

/*
 *  PHP implementation of Kernighan and Ritchie's example
 *  pseudorandom number generator.
 *
 *  By Matthew Kerwin, 2008.
 *
 *  Based on: http://computer.howstuffworks.com/question697.htm
 */

function kr_srand($seed) {
    
$GLOBALS['kr_random_seed'] = intval($seed);
}

function 
kr_rand($min 0$max 32768) {
    if (!isset(
$GLOBALS['kr_random_seed'])) {
        
$GLOBALS['kr_random_seed'] = mt_rand();
    }
    
$n intval($GLOBALS['kr_random_seed'] * 1103515245);
    while (
$n 0) {
        
$n += 2147483647;
    }
    
$n += 12345;
    
$GLOBALS['kr_random_seed'] = $n;

    return (
intval($GLOBALS['kr_random_seed'] / 65536) % ($max $min)) + $min;
}

?>