Skip to content
View in the app

A better way to browse. Learn more.

The AVSIM Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Rand in XML

Featured Replies

Nick had asked that I post my Random Macro. I converted a Fortran Rand function to this: 785398165 (L:Ran,number) * 422649731 + 2000000000 % d (>L:Ran,number) (* Saved Variable *) 2000000000 / (*out*) The top of the stack contains the result. In the range of 0.000 to 1.000. Shorter intergers would do OK, but I only had the double precision function available. The integers are special values thata give a good random distribution. XML supports the length OK and shorter variables would probably not be any faster. I tested it and the average value of many calls approaches 0.50. The 'RMS' is also correct. Approaching 1/sqrt(3). One could use "@Rand 0.1 * 0.05 -" to add a randomness to, say a gauge variable. Adding the above to the value would result in a new variable that would move around +/- 0.05 from the normal value. Each invocation generates a new Random on the stack. Note there is no way to seed the above Macro. However, that could be added if one needed the sequence to start at an arbitrary value. Ron

Thanks Ron. This demonstrates the principal, 785398165 (L:Ran,number) * 422649731 + 2000000000 % d (>L:Ran,number) (* Saved Variable *) 2000000000 / (*out*) %(@Rand 0.1 * 0.05 -)%!+4.2f!

>Thanks Ron. This demonstrates the principal, Glad it worked. ;)>>>> >> 785398165 (L:Ran,number) * 422649731 + 2000000000 % d> (>L:Ran,number) (* Saved Variable *)> 2000000000 / (*out*) > (Display result in message above) Now most 'random' variations follow the 'Normal', 'Bell Curve'. One can approximate this distribution by adding several rectangular distributions (such as from @Rand), then dividing by sqrt (n). @Rand @Rand @Rand + + 3 sqrt / Untested, but should give a distribution that varies from -3/sqrt(3) to +3/sqrt(3). One can replace the "3 sqrt /" with "0.57735 *", so the stack top varies from -1.7321 to 1.7321. But, peaked at 0.000. Both the Variance and RMS should be 1.00. If one added a little variation to either the throttle inputs or the RPM readings on multi-engine AC, he would then eliminate the RPM, fuel flow, etc. from being exactly the same for each powerplant. A slight offset might also be reasonable. Or, only a random offset might be added to each of the throttle settings. Generally, the RPM's, etc. are pretty steady in real AC, but are never exactly the same. After all, the throttles are not locked as in FS. I also created AVG and RMS Macros. Actually, I wanted to see the 'RMS' variation of Commanded pitch against Actual pitch when turbulence was present. I later used them on my Rand to check it out. One needs a variation in the name and internal L:vars for each Average done. (* Updates AVG every 4 seconds *) (L:AVG1_Init,bool) ! if{ 1 (>L:AVG1_Init,bool) 1 (>L:NA1,enum) 0 (>L:AV1,number) } @1 (L:AV1,number) + d (>L:AV1,number) (L:NA1,enum) / (* Add to Average *) (L:NA1,enum) @2 >= (* Every Samplers/18.2 *) if{ (>L:AVG1,number) 0 (>L:AV1,number) 0 (>L:NA1,enum) } (* Average *) (L:NA1,enum) ++ (>L:NA1,enum) (* @AVG1(Var,Samples) *) 'Samples' refers to number of times the Macro averages the '@1' input. At 18.2 ticks per second, the below would put a new Average in (L:Random,number) every four seconds:@AVG1(@Rand,72) (L:AVG1,number) (>L:Random,number) Note AVG1's output is in (L:AVG1,number), not at the top of the stack. A small variation could leave it on the stack, so the middle term above wouldn't be needed. A 'Running Average' (exponentially weighted filter) is even shorter; it weights recent values more than values farther in the past, and has the advantage that it gives a new value on every tick. Essentially, it amounts to a Low Pass Filter, filtering out noise depending on the Time Constant (TC) set. However, the "Filter" also requires two internal weighting factors to be calculated, and that adds some to the complexity. So, I won't lengthen this message even more with the code. I expect FS uses a similar Function to make things like CHT come up slowly, rather than all at once. I ID'ed one CHT parameter in the AIR file as '1/TC'. Similar for Oil Temp, EGT, etc. Ron

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.