<?php // Script Copyright 2020 Econfirmpro Contact: webmaster@econfirmpro.com


$ord_out = "";
$ordinator = array();
for($x=0;$x<10001;$x++){
	$ordinator[] = "$x";
}

shuffle($ordinator);
$ord = implode(",",$ordinator);
$ord = "," . $ord . ",";
for($x=10001;$x>0;$x--){
	$plug = "," . $x . ",";
	$ord = str_replace("$plug",",",$ord);


$temp1 = $ord;
$temp1 = ltrim($temp1, ",");
$temp1 = rtrim($temp1, ",");
	$ord_out .= $temp1;
	$ord_out = str_replace(",,",",", $ord_out);
	$ord_out .= "\n";

	if ($x % 100 == 1) {

		$ord_out_array = explode("\n", $ord_out);
		array_pop($ord_out_array);
		$temp_array = array_reverse($ord_out_array);
		$ord_out = implode("\n", $temp_array);

		if($x !== 10001) {


			$filename = __DIR__ . "/ordinator/ord_" .  $x . ".txt";

																							
						$file = fopen("$filename","w+");

						// exclusive lock
						if (flock($file,LOCK_EX)) {
							fwrite($file,$ord_out);
						  	fflush($file);
						 	 // release lock
						  	flock($file,LOCK_UN);
						} else {
						 	 echo "Error locking file!";
						}
						fclose($file);	

		}
		//unset($ord_out);
		$ord_out = "";
	}

}



		$ord_out_array = explode("\n", $ord_out);
		array_pop($ord_out_array);
		$temp_array = array_reverse($ord_out_array);
		$ord_out = implode("\n", $temp_array);

			$filename = __DIR__ . "/ordinator/ord_0.txt";

						$file = fopen("$filename","w+");

						// exclusive lock
						if (flock($file,LOCK_EX)) {
							fwrite($file,$ord_out);
						  	fflush($file);
						 	 // release lock
						  	flock($file,LOCK_UN);
						} else {
						 	 echo "Error locking file!";
						}
						fclose($file);	



echo "Ordinator Completed";


?>
