• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    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.

FS2004 Odd / Even days

Messages
1,468
Country
italy
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
 
Test it with a modulo of 2... if it's a 1, then it's odd... if it's a 0, then it's even.
 
I ended up with this which does the job!
vololiberista
Code:
<!-- 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]
 
Last edited:
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
 
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

Answer change the 2 for 10
 
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.
 
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.
vololiberista
 
Here's a repost:

In the 'For What It's Worth' category, here's another XML Random Number generator. This one is based on a multiplicative linear congruential generator method described by Pierre L'Ecuyer in a 1988 Association for Computing Machinery paper. The code below generates a random number between (but never equal to) 0 and 1 every Update cycle. It has a period of 2.30584 X 10^18, meaning that at an Update cycle rate of 18, the pattern will not repeat for a little over 4 billion years.

Code:
<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 &lt; if{ l1 ++ s1 } l1
</Macro>

<Update>
 @XMLRandom (>L:RandomNumber,number)
</Update>

L'Ecuyer, Pierre, 1988, Efficient and Portable Combined Random Number Generators, Association for Computing Machinery.

Acknowledgements owed to Ron Freimuth, Nike Pike, and Tom Aguilo who have posted xml random number code in this forum (AVSIM gauges forum) before. The MLCG code above is another variety. Acknowledgement also to my son, Robbie, for writing the xml snippet based on the L'Ecuyer paper.

There are a few other good XML random number generators out there too.

Bob
 
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 &lt; 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 &lt; 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 &gt; (L:RandomNumber,enum) 68 &lt; 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>
.....................................
 
Here's another question regarding random numbers. A random number generator picks lets say from 0 to 100.
Using the criteria above if my number range is less than greater than range is also 0 - 100 then obviously I have 100% unreliability.
But if instead my range is 25-75 out of 0-100 what would my unreliabilty be? On the face of it 50% but being random numbers that might not be the case. I assume the mathematicians have a formula to work that out!!
vololiberista
 
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.
 
Thanks for that info. I might also use it for hot starts. i.e time above max EGT results in engine failure.
vololiberista
 
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.

Again I'm no mathematician, but parts of your explanation don't seem quite correct (at least to my pea brain that is).

The parts highlighted in red that the range 26-75 is 50% of 100 and 0.1 is 10% of 1.0 I can remember from my school days (of the Pre-Cambrian era!).

The implication of your explanation however suggests for example that in the case of wanting a 10% failure rate i.e ten times in a hundred I check for a randomly generated number below 0.1. 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. If a random number generator was that reliable! I would be winning the Super Enalotto every week!!!!
In practice I get a failure rate of 2%. I'm experimenting on what number will give me close to 10 times in a hundred. My guess is that it will be something between 0.3 and 0.4 or even 0.5.
vololiberista
 
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.

Not exactly. It means, in this case, that the probability of generating a number below 10% is 0.1. That doesn't mean that in any given real sequence that 10% of the numbers will be below 0.1. For example, if you generate a series of 10 random numbers the probability that they will all be greater than 0.1 is 0.349. If you generate 100 numbers that probability falls dramatically to 0.000027 This is finite so there's still a small chance that you won't generate a number below 0.1 in that sequence.
 
What I've ended up with is the code below. It does seem that to get a more or less guaranteed 10% the test number has to be above 0.1.

Also in the VC10 the checklist states to check gyro erection "after" the ground/flight switch is set to flight. This switching from one power source to another may kick the gyro into life. So the <element> in blue covers that eventuality leaving the crew to manually press the "erect" button about 50% of the time.
vololiberista
Code:
<!-- Standby Horizon needs Fast Erect -->
<Element>
      <Select>
         <Value>(L:RandomNumber,number) 0.105 &lt; (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 &lt; (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]
 
Last edited:
If you want guarantee that the next 100 flights have 10 gyro failures then you should take a different approach.
The method I described is tossing coins.
Over a long period the distribution will be roughly 50-50 but individual tosses have no relation others.
Over a short period no distribution is more likely than another, it is after all random.

Consider a deck of cards that is shuffled.
You know that it contains 4 kings but you do not know where they are in the deck.
To get a guaranteed 10 failures in 100 flights you must build a similar deck of cards.
This basically is a list of booleans where 10 are set to true and 90 to false.
The list is shuffled ONCE so that the locations of the trues are unknown.
Then at the start of each flight a card is drawn from the list (first card 1, then card 2, etc) and it's value will determine if there will be a failure.
When you have drawn the last card the list is shuffled again so you won't repeat the previous sequence.
Unless you want to keep the sim running for 100 flights you will need to save the list to disk.
 
Back
Top