Revision: 58884
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at August 8, 2012 03:53 by eortiz
Initial Code
<?php /** * Returns a true random number from RANDOM.ORG's integer * http interface. Requires cURL. * * @author Bo Allen * @param int $min (Optional) Minimum number (default 1) * @param int $max (Optional) Maximum number (default 100) * @return mixed Random number (int) on success, * error or message (string) on failure */ function get_true_random_number($min = 1, $max = 100) { // Validate parameters $max = ((int) $max >= 1) ? (int) $max : 100; $min = ((int) $min < $max) ? (int) $min : 1; // Curl options $options = array( CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => '', CURLOPT_USERAGENT => 'PHP', CURLOPT_AUTOREFERER => true, CURLOPT_CONNECTTIMEOUT => 120, CURLOPT_TIMEOUT => 120, CURLOPT_MAXREDIRS => 10, ); // Curl init & run $ch = curl_init('http://www.random.org/integers/?num=1&min=' . $min . '&max=' . $max . '&col=1&base=10&format=plain&rnd=new'); curl_setopt_array($ch, $options); $content = curl_exec($ch); curl_close($ch); return trim($content); }
Initial URL
Initial Description
Random function, thanks to (http://boallen.com/php-get-true-random-number.html "Bo Allen")
Initial Title
Random numbers from random.org
Initial Tags
Initial Language
PHP