Jump to content

Any help to get three random unique flags values :?


Recommended Posts

Posted (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 by Presidium
Posted
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

  • Thanks 1
Posted (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:

 

pmPvzWU.jpg

 

Then regenerate the 2nd number until it is different from the other two:

 

RNpnyxr.jpg

 

Finally, regenerate the third number until it too is different from the others:

 

3bVqBom.jpg

 

For testing, the last triggers displays the three flags:

 

6LdzqiZ.jpg

 

Runs like this:

 

Ih5MCbD.jpg

 

Here is the mission if you want to try it:

 

Test Random Numbers.miz

Edited by Rudel_chw
  • Like 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

Posted (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 by Presidium
  • Like 3
Posted

@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).

issue.jpg

Test Random Numbers-every-4-sec.miz

  • Thanks 1
Posted
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:

 

UHKmERh.jpg

 

I tested this a lot of times and now seems to work well 🙂

Test Random Numbers.miz

  • Like 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

Posted
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

Posted

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

 

Posted
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

Posted (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 by dark_wood
  • Like 1
  • Thanks 1
Posted (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 by Elphaba
  • Like 1
  • Thanks 1
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...