Jump to content

Recommended Posts

Hello everyone,

 

if you want to know exactly how the random command behaves with your own values then here is just a small function to test it with "random [min,mid,max]". Output is similar to the example 4 on the Biki page.

 

/*
	Author: Terra

	Parameters:
	1: Number - Minimum
	2: Number - Middle
	3: Number - Maximum
	(Optional) 4: Number - Runs, higher numbers take longer
		*Default: 100000
	(Optional) 5: Number - Return specific element
		*Default: -1 (return all)
	(Optional) 6: String - Round method, can be "round","ceil","floor"
		*Default: "round"

	Return:
	Array of arrays OR with param 4: array

	Example:
	0 = [0,5,10] call TER_fnc_randomTest;
*/

TER_fnc_randomTest = {

	params [ "_min","_mid","_max", ["_runs",10^5, [123]], ["_spec",-1,[123]], ["_mode","round", ["string"]]];
	private ["_random"];

	_minMidMaxArr = [_min,_mid,_max];

	_countArray = [];
	for "_i" from 1 to _runs do {
		switch _mode do {
			case "round": {_random = round random _minMidMaxArr};
			case "ceil": {_random = ceil random _minMidMaxArr};
			case "floor": {_random = floor random _minMidMaxArr};
		};
		_countArray pushBack _random;
	};

	_outputArray = [];
	_biggest = selectMax _minMidMaxArr;
	_smallest = selectMin _minMidMaxArr;
	for "_h" from _smallest to _biggest do {
		_count = {_x == _h} count _countArray;
		_outputArray pushBack ([_h,_count, 100*(_count/_runs)]); // Output as [Tested Number, occurences, probability %]
	};
	if (_spec != -1) exitWith {
		copyToClipboard str _outputArray;
		_output = _outputArray select _spec;
		systemchat str _output;
		_output
	};
	copyToClipboard str _outputArray;
	systemchat str _outputArray;
	_outputArray
};

:exclamation: Just a quick warning: This function can take up some time. It runs several thousand times after all.

 

See you around,

 

7erra

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×