- Messages
- 1,468
- Country

What would be the best formula to determine whether a day is an even number or odd number using (E:ZULU DAY OF YEAR, enum)?
vololiberista
vololiberista
Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.
By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.


<!-- Standby Horizon needs Fast Erect -->
<Element>
<Select>
<Value>(E:ZULU DAY OF YEAR, enum) 2 % (>L:oddoreven,bool)</Value>
</Select>
</Element>
<Element>
<Select>
<Value>(L:fast_erect,bool) 0 == (L:oddoreven,bool) 1 == and
if{ -250 (>L:Attitude indicator bank degrees,number) }
els{ (A:Attitude indicator bank degrees,radians) (>L:Attitude indicator bank degrees,number) }</Value>
</Select>
</Element>
[COLOR="Green"](L:fast_erect,bool) is the clickable button on the gauge.[/COLOR]

What is the significance of odd or even days?

Well, the idea is/was for the standby horizon to not erect sometimes. There's no "specific" reason for odd/even days.
I also thought to have the fault recur a little less frequently. For example every 10 days. But i'm not sure about how to calculate that in xml.
For example if (E:ZULU DAY OF YEAR, enum) =153 and I want to return 3 as the answer i.e. MOD
In excel the formula is =MOD(153,10) the resultant being 3.
how can I replicate that in xml?
vololiberista

Apart from making it less frequent, how about making it less regular as well?
Draw a random number when the gauge starts and if turns up less than a predefined chance the gauge fails.
You then tune that chance to get the desired amount of unreliability.

Currently I changed it to be every 19 days. Your idea is also good. I did see somewhere here how to do random numbers but can't seem to locate it.

<Macro Name="XMLRandom">
(L:RandomSeed1,number) 0 == (L:RandomSeed2,number) 0 == ||
if{
(P:Absolute Time,seconds) abs d 2147483563 % (>L:RandomSeed1,number)
sqrt d d * * abs 2147483599 % (>L:RandomSeed2,number)
}
(L:RandomSeed1,number) 40014 * 2147483563 % (>L:RandomSeed1,number)
(L:RandomSeed2,number) 40692 * 2147483399 % (>L:RandomSeed2,number)
(L:RandomSeed1,number) (L:RandomSeed2,number) - 2147483563 / s1 l1 0 < if{ l1 ++ s1 } l1
</Macro>
<Update>
@XMLRandom (>L:RandomNumber,number)
</Update>

<!-- Random Number Generator -->
<Macro Name="XMLRandom">(L:RandomSeed1,number) 0 == (L:RandomSeed2,number) 0 == ||
if{ (P:Absolute Time,seconds) abs d 2147483563 % (>L:RandomSeed1,number) sqrt d d * * abs 2147483599 % (>L:RandomSeed2,number) } (L:RandomSeed1,number) 40014 * 2147483563 % (>L:RandomSeed1,number) (L:RandomSeed2,number) 40692 * 2147483399 % (>L:RandomSeed2,number) (L:RandomSeed1,number) (L:RandomSeed2,number) - 2147483563 / s1 l1 0 < if{ l1 ++ s1 } l1</Macro>
<Element>
<Select>
<Value>(L:switch_pos,bool) 1 == (L:ran,bool) 0 ==
if{ @XMLRandom (>L:RandomNumber,enum) 1 (>L:ran,bool) (L:RandomNumber,enum) 100 * (>L:RandomNumber,enum) }
els{ (L:switch_pos,bool) 0 == if{ 0 (>L:ran,bool) } }</Value>
</Select>
</Element>

.....................................That's the same one I found on avsim! Though I do get 0 and 100 because I multiplied by 100 and then created an integer. I ended up with this. Rather than a single number I have a range which I'm testing in terms of failure frequency. Narrowing the range will of course increase reliability!
In the code below the random generator runs until the master switch is on (L:switch_pos,bool) 1 ==
vololiberista
Code:<!-- Random Number Generator --> <Macro Name="XMLRandom">(L:RandomSeed1,number) 0 == (L:RandomSeed2,number) 0 == || if{ (P:Absolute Time,seconds) abs d 2147483563 % (>L:RandomSeed1,number) sqrt d d * * abs 2147483599 % (>L:RandomSeed2,number) } (L:RandomSeed1,number) 40014 * 2147483563 % (>L:RandomSeed1,number) (L:RandomSeed2,number) 40692 * 2147483399 % (>L:RandomSeed2,number) (L:RandomSeed1,number) (L:RandomSeed2,number) - 2147483563 / s1 l1 0 < if{ l1 ++ s1 } l1</Macro> <Element> <Select> <Value>(L:switch_pos,bool) 1 == (L:ran,bool) 0 == if{ @XMLRandom (>L:RandomNumber,enum) 1 (>L:ran,bool) (L:RandomNumber,enum) 100 * (>L:RandomNumber,enum) } els{ (L:switch_pos,bool) 0 == if{ 0 (>L:ran,bool) } }</Value> </Select> </Element> <Element> <Select> <Value>(L:RandomNumber,enum) 63 > (L:RandomNumber,enum) 68 < and (L:fast_erect,bool) 0 == and (L:switch_pos,bool) 1 == and if{ -250 (>L:Attitude indicator bank degrees,number) } els{ (A:Attitude indicator bank degrees,radians) (>L:Attitude indicator bank degrees,number) }</Value> </Select> </Element>



If you draw a random integer number between 1 and 100 then the chance of drawing any particular number is 1%.
the chance of it being in a particular range would then b the number of integers inside that range.
26-75 has 50 integers in the range so the chance will be 50%, just like 1-50 or 44-93.
What I do is generate a number between 0 and 1.
Then I compare that to a preset chance (0 to 1) of something happening.
If the random number is less than the chance something happens, otherwise something does not happen.
For example, every time you start the plane there is a 10% (=0.1) chance of the attitude gyro not erecting.
So when the plane is started the ADI gauge will draw a random number.
If the number is less than 0.1 the gyro fails.
If you want something to happen at a random moment with a chance of once in timeperiod x then you cut that timeperiod into smaller periods.
Then you determine the chance of somthing happening in one particular period.
This is 1/number of periods.
For example, the fuelfilter will get clogged on average once an hour.
I want to test this each second so I divide the hour in 3600 periods.
The chance of the filter clogging this second is 1/3600 or 0.0000278 or 0.02 %.
Then every second I draw a random number. If it is less than 0.0000278 the filter is clogged and the engine quits.
That implies does it not that the random generator will always generate numbers below 0.1 10% of the time i.e. ten times in a hundred.

<!-- Standby Horizon needs Fast Erect -->
<Element>
<Select>
<Value>(L:RandomNumber,number) 0.105 < (L:fast_erect,bool) 0 == and (L:switch_pos,bool) 1 == and
if{ -250 (>L:Attitude indicator bank degrees,number) }
els{ (A:Attitude indicator bank degrees,radians) (>L:Attitude indicator bank degrees,number) }</Value>
</Select>
</Element>
[COLOR="Blue"]<Element>
<Select>
<Value>(L:RandomNumber,number) 0.055 < (L:fast_erect,bool) 0 == and (L:Attitude indicator bank degrees,number) -250 == and (L:flight,enum) 1 == and
if{ (A:Attitude indicator bank degrees,radians) (>L:Attitude indicator bank degrees,number) 1 (>L:fast_erect,bool) }</Value>
</Select>
</Element>[/COLOR]