$max) { list($min, $max)=[$max, $min]; } $delta=$max-$min; if($delta<0||$delta>PHP_INT_MAX) { gen_error_500("\$c_random_int(): \$delta is not between 0 and PHP_INT_MAX(".(string)PHP_INT_MAX.")"); exit; } $t=$delta; $res=0; for($a=0; $t>0; $a++) { $res<<=8; $res|=unpack("C", $GLOBALS["c_random_int_seed"][$a&63])[1]; //&63 is equal to %64 $t>>=8; } unset($a); $res&=$delta; //avoid mod(%) operator, as it makes the result not evenly distributed $GLOBALS["c_random_int_seed"]=hash("sha512", $GLOBALS["c_random_int_seed"], true); return $min+$res; }; //the function make_attachment_impl($team_hash) should return an array [(string)filename, (string)file_content] on success, or boolean false if it failed to generate. $fn=make_attachment_impl($thash); if($fn===false||!is_array($fn)||count($fn)!=2||gettype($fn[0])!="string"||gettype($fn[1])!="string") { $out="failed to make attachment for challange ".$proj["name"].": function call to make_attachment_impl(\$team_hash) failed or the returned value is invalid."; if(gettype($fn)=="string") { $out.="\nThe generator returned the following error:\n"; $out.=$fn; } gen_error_500($out); exit; } if(strlen($fn[0])<=0) { $fn[0]="attachment.bin"; } return $fn; }