Show TOC

Background documentationRandom Number Expression

 

You use the random number expression to intentionally integrate an unpredictable element into your application. This can be useful for test purposes when you want to check how an application behaves through many iterations with permanently changing input parameters. Another possible use case could be to let this expression calculate a value that you might assign automatically to mass objects in your application (provided that no systematic numbering is needed for that), like customer ID, order number, and so on.

The random number expression is based on the standard ABAP pseudo-random number generator. Whenever the expression is evaluated, this number generator is started in the backend with a new seed value to ensure that the generated number sequence is different.

Note Note

Keep in mind that the algorithm used for generating random numbers is made for normal business use cases only. This is because the generated number sequences are identical as long as the same seed value is used. Therefore, the random number expression is neither intended nor sufficient for security-relevant purposes like password encryption, access codes, or any other kind of cryptographic use cases.

End of the note.

Features

Modes of Operation

The random number expression offers two modes of operation: The expression can either return a random number between two boundaries (minimum and maximum) or return a boolean value with a user-defined probability between 0 and 1.

  • Number

    In this mode, the expression returns a random number between two borders (minimum and maximum). You can influence the range of possible results not only by these two borders, but also by setting the number of decimals. Here, the maximum number of decimals depends on the definition of the result data object that is assigned to the expression.

  • Probability

    In this mode, the expression returns a boolean value. You can fine-tune the expression behavior by setting the statistical probability for the expression to return the value TRUE. The probability value is given as a decimal fraction between 0 and 1, with a maximum of three decimals. A probability of 1 means that the expression returns always TRUE.

    Note Note

    You can take a look behind the scenes by simulating a random number expression. Here, you see that even in probability mode, the expression internally still calculates a random number. However, this number is not used as the expression result but as an operand of an internal comparison operation: The expression checks whether the calculated number is less than or equal to the value passed as context to the expression. If so, the expression returns TRUE, otherwise FALSE.

    End of the note.
Value Assignment

If you have set the mode of operation to Number, you can choose between the following ways of defining values for the sample space:

  • Direct Input

    In direct input mode, you define the values for the lower and upper boundaries of the sample space directly. As a consequence, there is no need for context data objects in this mode. For the system, this static value assignment is easy to check so that potential errors can already be detected at design time.

  • Reference

    In reference mode, you define the values for the lower and upper boundaries of the sample space indirectly by assigning a context data object or an expression to each of the boundaries, rather than defining a fixed static value. This dynamic value assignment gives you more flexibility at runtime. However, it also increases the risk of formal errors (like a minimum value higher than the maximum value) that can lead to an exception.

Automatic Adjustments

BRFplus helps you defining a random number expression with several checks that are either running in the background or that you trigger with the Check button:

  • When you create the expression in number mode, BRFplus automatically assigns the built-in data object NUMBER to it as the result data object. In most cases, this is exactly what you need since the result of a random number expression is always a numeric value. However, you are still free to choose a user-defined data object of type number.

    If you create the expression in probability mode, the same applies, but with the built-in data object BOOLEAN.

  • In direct input mode for numbers, the system automatically swaps the values for minimum and maximum if the minimum value is greater than the maximum value.