Jump to content
Sign in to follow this  
roguetrooper

random in forEach

Recommended Posts

Will every unit end up with the same skill or will every unit have a different skill when you execute

{_x setSkill ["aimingAccuracy", 0.1 + (random 0.9)]} forEach allUnits;

?

I wanted to find out by myself by this testing code, but there is an error message "missing ;"

_idx = -1;
_list = [0,0,0,0,0,0,0,0,0,0];
{_idx = _idx+1; _list (select _idx) = (random 1);} forEach _list;
hint str _list;

So what happens to each element in an forEach-array when you involve randomness? Will every soldier have the same skill?

Share this post


Link to post
Share on other sites

Yeah, you do get a random number generated for each element in your array.

Here's a quick test you could have performed:

{
_test = 0.1 + random 0.9;
player sidechat format ["Iteration : %1 \nValue : %2", forEachIndex, _test];
} forEach [0,1,2,3,4,5,6];

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
Sign in to follow this  

×