PHP: Get True Random Number
/**
* Get True Random Number
* Returns a true random number from RANDOM.ORG's integer http interface. Requires cURL.
* @author Bo Allen
* @return Int random number on success, String error or message on failure
* @param Int $min minimum number
* @param Int $max maximum number
*/
function get_true_random_number($min, $max) {
// validate parameters
if (!is_numeric($min)) {
$min = 1;
}
if (!is_numeric($max)) {
$max = 10;
}
// 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);
}