Presidium Posted November 7, 2022 Posted November 7, 2022 (edited) Hi guys, I'm asking for some help here. I need to get some three random numbers from 1 to 10. Flag01 set random value: 1 - 10 Flag02 set random value: 1 - 10 Flag03 set random value: 1 - 10 But they must be unique, and cannot be repeated. Three different flags with three different values. I know I can do it with a bunch of FLAG EQUAL FLAG and FLAG IS LESS THAN FLAG checks. But it's so tedious and long, and it has no sense to make so many triggers and conditions for such easy piece of code... (I wish there was a FLAG NOT EQUAL FLAG). Any help would be greatly appreciate! Thank you! Edited November 7, 2022 by Presidium Youtube - Official Website
toutenglisse Posted November 7, 2022 Posted November 7, 2022 5 hours ago, Presidium said: ...Three different flags with three different values... Hi, here a script to do that (and a .miz to test -> flags are defined every 5 seconds with message that gives values) : local values = {1,2,3,4,5,6,7,8,9,10} for j = 1, 3 do local i = math.random(#values) trigger.action.setUserFlag("0"..j, values[i]) table.remove(values, i) end test-3flags-unique-rand-value-1-10.miz 1
Chump Posted November 8, 2022 Posted November 8, 2022 (edited) @toutenglisse has the right answer here with minimal processing. Edited November 9, 2022 by Chump I missed the "unique, and cannot be repeated" part 1
toutenglisse Posted November 8, 2022 Posted November 8, 2022 7 hours ago, Chump said: for i = 1, 3 do trigger.action.setUserFlag(tostring(i), math.random(10)) end In your example, nothing prevents results to be the same.
Rudel_chw Posted November 8, 2022 Posted November 8, 2022 (edited) 21 hours ago, Presidium said: Any help would be greatly appreciate! Hi, My take would be like this, first generate the three random values: Then regenerate the 2nd number until it is different from the other two: Finally, regenerate the third number until it too is different from the others: For testing, the last triggers displays the three flags: Runs like this: Here is the mission if you want to try it: Test Random Numbers.miz Edited November 8, 2022 by Rudel_chw 2 For work: iMac mid-2010 of 27" - Core i7 870 - 6 GB DDR3 1333 MHz - ATI HD5670 - SSD 256 GB - HDD 2 TB - macOS High Sierra For Gaming: 34" Monitor - Ryzen 3600 - 32 GB DDR4 2400 - nVidia RTX2080 - SSD 1.25 TB - HDD 10 TB - Win10 Pro - TM HOTAS Cougar Mobile: iPad Pro 12.9" of 256 GB
Presidium Posted November 8, 2022 Author Posted November 8, 2022 (edited) Wow! I love to see so different approachs to the same problem! Removing values for a table was a neat idea toutenglisse! But I will stay with Rudel_chw approach: just 3 lines and do not have to use a script/predicate LUA. Clean, fast and easy, just perfect! I'm working on a civilian mission for the huey and you've save me so many lines of checkings and conditions! Thanks **A LOT** guys! I TRULY APPRECIATE YOUR HELP!! I love you ALL!!! :))) Edited November 8, 2022 by Presidium 3 Youtube - Official Website
toutenglisse Posted November 9, 2022 Posted November 9, 2022 @Presidium and @Rudel_chw, I've tested Rudel's random number miz and I can't say why, but same numbers still happen. Attached modified miz (modified the 3 flags trigger to fire every 4 seconds, and added a time message and made the messages continuous - updated every second) I tested because my hesitation with this method was : maybe flags would still be activated with potential same numbers and detected like this before being changed, due to "switched cond" triggers being evaluated every sec. But it seems that this is not an issue, while there is another one. (unidentified, but soon or late flags are activated with same numbers) FWIW with script the 2nd and 3rd flags can only be activated with values from 1 to 10 but without value(s) of previous flag(s). Test Random Numbers-every-4-sec.miz 1
Rudel_chw Posted November 10, 2022 Posted November 10, 2022 On 11/9/2022 at 10:19 AM, toutenglisse said: I've tested Rudel's random number miz and I can't say why, but same numbers still happen. ... I tested because my hesitation with this method was : maybe flags would still be activated with potential same numbers and detected like this before being changed, due to "switched cond" triggers being evaluated every sec. But it seems that this is not an issue, while there is another one. (unidentified, but soon or late flags are activated with same numbers) Hi @toutenglisse .. you are correct, I tested my triggers more times and it did in fact sometimes generated repeated numbers .. my two SWITCHED CONDITION loops were not working properly. I had to add two explicit flags to get the loops to work: I tested this a lot of times and now seems to work well Test Random Numbers.miz 2 For work: iMac mid-2010 of 27" - Core i7 870 - 6 GB DDR3 1333 MHz - ATI HD5670 - SSD 256 GB - HDD 2 TB - macOS High Sierra For Gaming: 34" Monitor - Ryzen 3600 - 32 GB DDR4 2400 - nVidia RTX2080 - SSD 1.25 TB - HDD 10 TB - Win10 Pro - TM HOTAS Cougar Mobile: iPad Pro 12.9" of 256 GB
toutenglisse Posted November 11, 2022 Posted November 11, 2022 On 11/10/2022 at 8:50 PM, Rudel_chw said: ...I tested this a lot of times and now seems to work well Hey, I just took a look and still same flags values occures. No clue what's wrong though.
Rudel_chw Posted November 11, 2022 Posted November 11, 2022 1 hour ago, toutenglisse said: Hey, I just took a look and still same flags values occures. No clue what's wrong though. I've checked and re-checked my logic, and can't find the fault ... pity For work: iMac mid-2010 of 27" - Core i7 870 - 6 GB DDR3 1333 MHz - ATI HD5670 - SSD 256 GB - HDD 2 TB - macOS High Sierra For Gaming: 34" Monitor - Ryzen 3600 - 32 GB DDR4 2400 - nVidia RTX2080 - SSD 1.25 TB - HDD 10 TB - Win10 Pro - TM HOTAS Cougar Mobile: iPad Pro 12.9" of 256 GB
Exorcet Posted November 11, 2022 Posted November 11, 2022 Perhaps something is up with Switched Condition. I think I made a unit spawner that had to randomize the order of 4 groups, but it used Continuous Action if I recall. Maybe that trigger type will work as expected? Awaiting: DCS F-15C Win 10 i5-9600KF 4.6 GHz 64 GB RAM RTX2080Ti 11GB -- Win 7 64 i5-6600K 3.6 GHz 32 GB RAM GTX970 4GB -- A-10C, F-5E, Su-27, F-15C, F-14B, F-16C missions in User Files
Rudel_chw Posted November 11, 2022 Posted November 11, 2022 1 hour ago, Exorcet said: Maybe that trigger type will work as expected? The problem with Continuous triggers is that they execute once per second from the start up to the finish of the mission, not only producing overhead, but on this case it wouldn't be useful that the trigger altered the numbers after the moment the were needed. For work: iMac mid-2010 of 27" - Core i7 870 - 6 GB DDR3 1333 MHz - ATI HD5670 - SSD 256 GB - HDD 2 TB - macOS High Sierra For Gaming: 34" Monitor - Ryzen 3600 - 32 GB DDR4 2400 - nVidia RTX2080 - SSD 1.25 TB - HDD 10 TB - Win10 Pro - TM HOTAS Cougar Mobile: iPad Pro 12.9" of 256 GB
dark_wood Posted November 11, 2022 Posted November 11, 2022 (edited) Hi guys, nice logic challenge I have modified a little Rudel's approach (thanks @Rudel_chw for template) , see attached. Basically, i have generated the flags one after other: first flag is generated, the after 1 second, flag two comes and check if is equal with F1. If yes, regenerate, else, after 1 second, Flag 3 enters, check again, regenerate if equal with F1 or F2, else all good, show result after TIME MORE 20 seconds. I did several tests, all seems ok, but let me know your test results. At the end, the little snippet shared by @toutenglisse seems the easier solution here. Test_Random_Numbers.miz Edited November 11, 2022 by dark_wood 1 1
TEMPEST.114 Posted November 11, 2022 Posted November 11, 2022 (edited) And this is my 'script' version (tested and working) that is far quicker and easier than using the ME and setting flags etc.. --------------------------------------------------------------------------------------------------- -- ************************************************************************************************ --------------------------------------------------------------------------------------------------- -- *** Usage *** --------------------------------------------------------------------------------------------------- -- ************************************************************************************************ --------------------------------------------------------------------------------------------------- -- 1. Create a MISSION START Trigger, with no condition and the action of do script file and load this file. -- 2. Then when you want to generate them, create a trigger with the action of 'do script' and do this: -- RFVG:SetFlagsToRandomValuesBetweenMinAndMax(1, 10, "A", "B", "C", false) -- The last value - if true will output to the screen for everyone. If false then it won't. The 1 and 10 are the MIN and MAX - change these however you want with each call you make. A, B and C are the flags you're using, either numbers or words but they have to be in the quotes. RFVG.lua Edited November 11, 2022 by Elphaba 1 1
Recommended Posts