/*
	Author: Tom_48_97

	Description:
	Return a random value between min and max. Note that if #0 > #1, the function will swap vars.
	If the random result is lower than min, it returns the min. Same for the max value.

	Parameter(s):
	#0 NUMBER - The minimal value
	#1 NUMBER - The maximum value
	#2 BASE - Random result type: "round", "floor", "ceil", "float". Any other value will return a float

	Example of use:
	this setFuel ([0.2, 0.5] call tm4_fnc_random);
	this setPosATL [(getPosATL player select 0) + ([5, 10, "floor"] call tm4_fnc_random), (getPosATL player select 1) + ([3, 7, "floor"] call tm4_fnc_random), 0.1];

	Returns:
	NUMBER - Integer or float
*/

private["_this", "_min", "_max", "_base", "_return"];
_min = [_this, 0, 0, [0]] call bis_fnc_param;
_max = [_this, 1, 1, [0]] call bis_fnc_param;
_base = [_this, 2, "float", ["round", "floor", "ceil", "float"]] call bis_fnc_param;

if !(typeName _min == typeName 0) exitWith {["#0: Must be a NUMBER"] call bis_fnc_error;};
if !(typeName _max == typeName 0) exitWith {["#1: Must be a NUMBER"] call bis_fnc_error;};

if (_min > _max) then
{
	private ["_tmp1", "_tmp2"];
	_tmp1 = _min;
	_tmp2 = _max;

	_max = _tmp1;
	_min = _tmp2;
};

_base = toLower(_base);
_return = random _max;

switch (_base) do
{
    case "round":	{_return = round(_return);};
    case "floor":	{_return = floor(_return);};
    case "ceil":  	{_return = ceil(_return);};
};

if (_return < _min) Then {
	_return = _min;
};
if (_return > _max) Then {
	_return = _max;
};

_return