/*	kd:
	
	This circumvents a very terrible multiplayer desync.
	
	A nuclear middlefinger to whomever it may concern.
	
	*/

class Gc_Rng {
	const binary_size		= 16;
	const whole_size		= 64;
	const unit_size			= 64;
	
	// kd: Some random numbers stored for later.
	protected int					binary_	[binary_size];
	protected int					whole_	[whole_size];
	protected double				unit_	[unit_size];
	
	protected int					binary_counter;
	protected int					whole_counter;
	protected int					unit_counter;
	
	// kd: These are clientsided, so be careful.
	protected int					binary_client;
	protected int					whole_client;
	protected int					unit_client;
	
	void OnBuild () {
		binary_counter	= 0;
		whole_counter	= 0;
		unit_counter	= 0;
		binary_client	= 0;
		whole_client	= 0;
		unit_client		= 0;
	}
	
	void Next () {
		binary_	[binary_counter]	= random(0, 1);
		whole_	[whole_counter]		= random(0, 1337);
		unit_	[unit_counter]		= frandom(0, 1);
		
		binary_counter++;
		whole_counter++;
		unit_counter++;
		
		if(binary_size <= binary_counter) {
			binary_counter = 0;
		}
		
		if(whole_size <= whole_counter) {
			whole_counter = 0;
		}
		
		if(unit_size <= unit_counter) {
			unit_counter = 0;
		}
	}
	
	double Unit () {
		let f = unit_ [unit_client];
		
		unit_client++;
		
		if(unit_size <= unit_client) {
			unit_client = 0;
		}
		
		return f;
	}
	
	double Real (double min_f, double max_f) {
		return min_f + Unit() * (max_f - min_f);
	}
	
	int WholeRange () {
		let i = whole_ [whole_client];
		
		whole_client++;
		
		if(whole_size <= whole_client) {
			whole_client = 0;
		}
		
		return i;
	}
	
	int Whole (int min_i, int max_i) {
		return min_i + WholeRange() % (max_i - min_i);
	}
	
	int Binary () {
		let i = binary_ [binary_client];
		
		binary_client++;
		
		if(binary_size <= binary_client) {
			binary_client = 0;
		}
		
		return i;
	}
}