From 0f3f522e250ee52c184a54d82f4b8dcbb9ac4eff Mon Sep 17 00:00:00 2001 From: worldwidesorrow Date: Thu, 9 Jan 2020 15:55:23 -0600 Subject: [PATCH] Replace slow array shuffle function with KK's Array Shuffle Plus KK's code is more efficient and you can enter how many times you want to shuffle. --- SQF/dayz_code/compile/fn_shuffleArray.sqf | 28 +++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/SQF/dayz_code/compile/fn_shuffleArray.sqf b/SQF/dayz_code/compile/fn_shuffleArray.sqf index bc5212339..d4147e8e2 100644 --- a/SQF/dayz_code/compile/fn_shuffleArray.sqf +++ b/SQF/dayz_code/compile/fn_shuffleArray.sqf @@ -1,13 +1,17 @@ -private ["_ar","_rand_array","_rand"]; -_ar = _this; -_rand_array = []; -while {count _ar > 0} do { - _rand = (count _ar); - _rand = floor (random _rand); - _rand_array set [count _rand_array, _ar select _rand]; - _ar set [_rand, "randarray_del"]; - _ar = _ar - ["randarray_del"]; - sleep 0.001; -}; +//Killzone Kid Array Shuffle Plus +//Usage: array = [array, shuffle count] call fn_shuffleArray; -_rand_array \ No newline at end of file +private ["_arr","_cnt","_el1","_indx","_el2"]; +_arr = _this select 0; +_cnt = count _arr - 1; +if (_cnt < 1) exitWith {_arr;}; // add count check to prevent errors. +_el1 = _arr select _cnt; +_arr resize _cnt; +for "_i" from 1 to (_this select 1) do { + _indx = floor random _cnt; + _el2 = _arr select _indx; + _arr set [_indx, _el1]; + _el1 = _el2; +}; +_arr set [_cnt, _el1]; +_arr