-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add CBA_fnc_selectRandomArray #1049
Conversation
Atm. this function has inconsistent behaviour about modifying the input array by reference. private _original = [1,2,3];
private _selected = [_original, 2] call CBA_fnc_selectRandom;
hint str _original; // [] vs. private _original = [1,2,3];
private _selected = [_original, 10] call CBA_fnc_selectRandom;
hint str _original; // [1,2,3] I think a function like this should not modify its arguments on the principle of avoiding side effects. The solution would be to deep copy after the _array = + _array; But if the array is itself made up of arrays, then it may be interesting to not copy these sub arrays as well, but to keep their references. This is an edge case, but I personally would expect that behaviour. This could be implemented easily by doing a shallow copy of the input array instead: _array = [] + _array; |
@commy2 I think deep vs shallow copy behaviour should be consistent across array functions (i.e. shuffle should also do shallow if that's done here - currently it does deep). |
Co-Authored-By: neilzar <neil.evers.1995@gmail.com>
Co-Authored-By: neilzar <neil.evers.1995@gmail.com>
OK, now all we need is a better name. |
I think |
Anyone else prefers |
|
It selects an array of elements out of an array as opposed to a single element out of an array. The name fits really well. |
When merged this pull request will:
Unsure if the function name is the best option, but I think it might become too long otherwise.