Random numbers

Top 

 

For simulation of disturbances you can let create random numbers by TrySim. For that four functions are available which you call with the key word FUNC x:

 

FUNC 100 creates a random number between 0 and (accu 1-L - 1) and stores this one in accu 1 again. The number in accu 1-L is interpreted as 16-bit integer.
FUNC 101 creates a random number between -accu 1-L and +accu 1-L. The number in accu 1-L is interpreted as 16-bit integer.
FUNC 102 creates a REAL number between 0 (included) and accu 1 (excluded). Accu 1 is interpreted as REAL number and can be negative as well.
FUNC 103 is similar to FUNC 100 but does not stores the random number in accu 1, but will set the RLO to ‘1’ if it equals 0. If the random number >0 the RLO will be set to ‘0’.

 

Examples:

      L    10

      FUNC 100     // In accu 1 is now a random number from 0 - 9

 

      L    5

      FUNC 101     // In the accu there is now a random number from -5 till +5

 

      L    10000

      FUNC 103     // With a chance of 1:10000 the RLO is now ‘1’

 

The operation FUNC cannot be exported because it is only defined within TrySim. That is why you should restrict the use of this operation to the OB2 and OB3 ( or to the blocks called there).

 

The example ‘Random’ demonstrates the four ways to create random numbers.

 

Please note also that the generator can create dynamics of random size.