Jump to content

Random with elimination?


Recommended Posts

How would a person generate a random value that eliminates that value on a second pass?

 

Ie:

 

Flag 1 min 1 max 17 ends up being 13... how do I make the cycle eliminate 13 the next time around?

 

Second set is 9... I want to eliminate 9...

 

 

Is it complicated or does something exist in a script?

 

The flags would be generated some time apart... up to 3 times.

 

If the worse thing that happens is a value appears a second time, it would just be an empty action... which in itself I suppose is "random" but if I can keep the action moving I'd like to try and just eliminate already chosen values from future random actions.

"ENO"

Type in anger and you will make the greatest post you will ever regret.

 

"Sweetest's" Military Aviation Art

Link to comment
Share on other sites

You would probably need a script that keeps track of the values that were already used. For example by using a table where the entry that corresponds to the random number will be marked as "already used" or will be removed. If then later a random number comes up again, the algorithm could either generate a new one until it finds one that is not yet used, or it could simply loop over the table to find the next greater value and use that as actual new random number.

Link to comment
Share on other sites

You have to build a table of previous values and compare the new value to the table content and reject the new value if it is in the table, or if not in the table then add it and proceed with the function.

 

:)

Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site.

Link to comment
Share on other sites

Maybe map results of the random function to real values, decreasing the possibilities each time. Example:

 

Result map initially is

1 --> 1

2 --> 2

3 --> 3

4 --> 4

5 --> 5

6 --> 6

7 --> 7

8 --> 8

9 --> 9

10 --> 10

First pass, random(1,10), result is 7. Consult map, do operation on 7.

 

New result map (without 7) is

1 --> 1

2 --> 2

3 --> 3

4 --> 4

5 --> 5

6 --> 6

7 --> 8

8 --> 9

9 --> 10

Next pass, random(1,9), result is 8. Consult map, do operation on 9.

 

New map (without 7 and 9) is

1 --> 1

2 --> 2

3 --> 3

4 --> 4

5 --> 5

6 --> 6

7 --> 8

8 --> 10

Next pass, random(1,8 ), result is 2. Consult map, do operation on 2.

 

New map (without 7, 9, and 2) is

1 --> 1

2 --> 3

3 --> 4

4 --> 5

5 --> 6

6 --> 8

7 --> 10

Next pass, random(1,7), result is 6. Consult map, do operation on 8.

 

And so on.

Link to comment
Share on other sites

Create a table with the values ordered, shuffle the contents around a few (~100?) times at random and use the table in sequence? Like a deck of cards.

 

No idea if this can be done in DCS, though, but after the initial shuffle it's very quick to find the next random number, and the same number would never be used again - no need to check for anything.

Dear Shilka. I hate you so very very much. Love, Rex

Link to comment
Share on other sites

something like this?

 

 

-- generate 3 times a random number and do something with the result
function flagRandomIndex(_cycle)
local _index = math.random(1, 17)
local _cycles = _cycle + 1

if _cycles <= 3 then
	trigger.action.outTextForCoalition(coalition.side.BLUE, string.format("Generate 3 times a random number in the range 1-17.\nOccurance: "..cycles.." random number: ".._index), 5)
	timer.scheduleFunction(flagRandomIndex, _cycles, timer.getTime() + 10)
else
	trigger.action.outTextForCoalition(coalition.side.BLUE, string.format("The flagRandomIndex counter has ended."), 10)		
end
end

-- start this construction
timer.scheduleFunction(flagRandomIndex, 0, timer.getTime() + 5)

 

 

[edit]: I understand now you want to keep track of generated numbers. Maybe something like this?

 

--the table of happened flags
indexHistory = {}

-- keep track of times to generate flag
cycles = 0

-- generate 3 times a random number and do something with the result
function flagRandomIndex()
local _index = math.random(1, 17)
local _indexFound = false

for i = 1, #indexHistory do
	if indexHistory[i] == _index then
		_indexFound = true
	end
end

if _indexFound then
	flagRandomIndex()
elseif _indexFound == false and cycles <= 2 then 
	flagRandomIndex[#flagRandomIndex + 1] = _index
	cycles = cycles + 1
	
	trigger.action.outTextForCoalition(coalition.side.BLUE, string.format("Generate 3 times a random number in the range 1-17. Random number: ".._index), 5)
	timer.scheduleFunction(flagRandomIndex, nil, timer.getTime() + 10)
end
end

-- start this construction
timer.scheduleFunction(flagRandomIndex, nil, timer.getTime() + 5)

 

 

 

 

 

.


Edited by piXel496
aah I have to read better I guess
Link to comment
Share on other sites

Thanks to those who responded... Sorry I'm utterly weak in this domain but I sure appreciate the input.

 

Pixel, your suggestion in particular caught my attention since from what I can gather from it, I can use that script in a do script function and it will spit out 3 random numbers- I'm just not certain how to attach that value to a particular flag. (1 in my case).

 

I was also taking a close look at Ajax' suggestion as it seemed to be in line with Crew's (by way of maps). That got me thinking about a way that may actually be really easy (was having a hard time last night getting my head around it).

 

 

Run the MIST random function for flag 1 (being the first cycle) between 1-17. Carry out that operation- whatever the flag value ends up being.

 

Run MIST random function for flag 2 (second cycle) and in the event of a flag 2 equals flag 1 then increase that flag value by 1.

 

Run MIST random function for flag 3 (3rd cycle) and in the event flag 2 = flag 3 or flag 3 = flag 1 then increase flag 3 by 1.

 

I can run an "if flag x is more than 17, decrease that flag value by 2. If flag x is less than 1, increase by 2.

 

Etc.

 

The easiest would definitely be to use a script instead to generate the 3 random values I need- the question is does that script link those 3 values to a particular flag? Or... more to the point- if I wanted to use this concept in the future- how do I control which action happens with a particular value?

 

I should have started with this- I am working on a rescue mission that will generate 1 rescuee position at a time for up to 3 cycles- maybe more... I guess we'll see how it goes. After each, I want to generate a new position.

 

I'm using Ragnarda's rescue script- and basically just activating and blowing up a unit straight away since it appears to reliably generate troops needing rescue (aircraft never seemed to guaranty a chute)... so depending on the flag value a unit is activated and then 2 seconds later it is "explode unit."

 

 

Make any sense? lol.

"ENO"

Type in anger and you will make the greatest post you will ever regret.

 

"Sweetest's" Military Aviation Art

Link to comment
Share on other sites

About forwarding the number into a flagname and based on the example above.

And although I am really lost if it is related to other script embedded constructions and I do not even know if a flag is a name or a number. Maybe something like:

 

flagIwantToGiveAnumber = _index
flagIwantToGiveAname = string.format("someText".._index) -- concatenate text with number into new text

 

 

 

 

 

.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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