Rommel 2 Posted May 29, 2005 Has anyone got any idea how to use the random command? What I'm trying to do is get a random out of 12. (for a shooting range) the targets are called t1 - t12. Share this post Link to post Share on other sites
korax 4 Posted May 29, 2005 <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_num = random 12 picks a random number between 0 and 12 to 3 decimal places But for your case it might be easier to use something like this <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_targetarray = [t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12] _target = _targetarray select (random 11) That uses the select command with the random command to pick a random array entry from the _targetarray Share this post Link to post Share on other sites
Rommel 2 Posted May 29, 2005 thanks mate. Trying it out now... Share this post Link to post Share on other sites
General Barron 0 Posted May 31, 2005 But for your case it might be easier to use something like this<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_targetarray = [t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12] _target = _targetarray select (random 11) That uses the select command with the random command to pick a random array entry from the _targetarray Err.. I don't think that will work. That would make calls like this: _targetarray select 8.523 I don't think OFP knows which index to select in such a case. However, with the 'mod' command, you can round numbers (see link). Or, you can use one of these functions: http://www.ofpec.com/editors/funcref.php?filter_func=39 http://www.ofpec.com/editors/funcref.php?filter_func=42 http://www.ofpec.com/editors/funcref.php?filter_func=27 Share this post Link to post Share on other sites
bn880 5 Posted May 31, 2005 Actually the select command in OFP does work with remainders of numbers present. It appears to do a standard round before selecting an array index. Perfectly safe, heavily used in some places. I'd say random 11.49 in that case not 11, but that's the idea. Cheers Share this post Link to post Share on other sites
5133p39 16 Posted May 31, 2005 and what about: _t = 1 + Random 11 _target = Format["t%1", _t - (_t % 1)] ...i think it's more flexible - no need for arrays Share this post Link to post Share on other sites
hardrock 1 Posted May 31, 2005 and what about:_t = 1 + Random 11 _target = Format["t%1", _t - (_t % 1)] ...i think it's more flexible - no need for arrays Arrays are only needed if you want to work with objects anyway. Share this post Link to post Share on other sites