-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add CBA_fnc_selectRandomArray (#1049)
* Initial commit * Fixes and improvements * Update addons/arrays/fnc_selectRandom.sqf Co-Authored-By: neilzar <neil.evers.1995@gmail.com> * Implement reviews * I want a min there * Add semicolon to please OCD Co-Authored-By: neilzar <neil.evers.1995@gmail.com> * Rename to selectSomeRandom * function name * update function name * update function name
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "script_component.hpp" | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_selectRandomArray | ||
Description: | ||
Select a specified amount of elements from an array without picking the same element multiple times. | ||
Parameters: | ||
_array - Input Array <ARRAY> | ||
_amount - Amount to select <NUMBER> | ||
Returns: | ||
New array with the specified amount of randomly selected elements <ARRAY> | ||
Example: | ||
(begin example) | ||
_result = [[1, 2, 3, 4, 5], 2] call CBA_fnc_selectRandomArray; | ||
// _result => [2, 4] (random) | ||
(end) | ||
Author: | ||
NeilZar | ||
---------------------------------------------------------------------------- */ | ||
SCRIPT(selectRandomArray); | ||
|
||
params [["_array", [], [[]]], ["_amount", 0, [0]]]; | ||
|
||
_amount = _amount min count _array; | ||
_array = + _array; | ||
|
||
private _result = []; | ||
|
||
for "_i" from 1 to _amount do { | ||
_result pushBack (_array deleteAt floor random count _array); | ||
}; | ||
|
||
_result |