/** * returns $bytes bytes of raw random data */ function common_random_rawstr($bytes) { $rawstr = @file_exists('/dev/urandom') ? common_urandom($bytes) : common_mtrand($bytes); return $rawstr; }
function common_good_rand($bytes) { // XXX: use random.org...? if (@file_exists('/dev/urandom')) { return common_urandom($bytes); } else { // FIXME: this is probably not good enough return common_mtrand($bytes); } }
/** * returns $bytes bytes of random data as a hexadecimal string */ function common_random_hexstr($bytes) { $str = @file_exists('/dev/urandom') ? common_urandom($bytes) : common_mtrand($bytes); $hexstr = ''; for ($i = 0; $i < $bytes; $i++) { $hexstr .= sprintf("%02x", ord($str[$i])); } return $hexstr; }