MicroStrategy ONE

Random number (between two values)

Returns a random number that falls between two specified values. The value returned is a real number, as opposed to an integer value.

A different number is returned each time the function is run. However, if the Randbetween function is used to modify multiple rows of values on a report, be aware that if you use a simple definition such as Randbetween(2, 10) the same random number will be applied to each row of data on the report. You can apply a different random number to each row of data in a report by including metric values in the Randbetween calculation, and an example of this is provided below.

Syntax

Randbetween(Bottom, Top)

Where:

Bottom is a real number or metric representing a list of real numbers that are the lowest value(s) the function can return; the bottom of the range. You can also include expressions that result in a real number value.

Top is a real number or metric representing a list of real numbers which are the highest value(s) the function can return; the top of the range. You can also include expressions that result in a real number value.

While Randbetween can accept real values as input values for Bottom and Top, the input values are processed differently based on the following:

  • Processed by the Analytical Engine: Functions provided with MicroStrategy can be evaluated by the MicroStrategy Analytical Engine in cases where functions cannot be evaluated by a database, or when features such as derived metrics use a function as part of their definition. When Randbetween is processed by the Analytical Engine, both input values are rounded down to the nearest integer value before determining a random number. For example, the expression Randbetween(0.5,1.6) for a derived metric will first round both input values down, making the resulting expression Randbetween(0,1). A random, real number is then returned between the values of 0 and 1.

    You can determine if a metric is processed by the Analytical Engine by looking at the SQL view of a report.

  • Processed by a database: Functions provided with MicroStrategy can be passed to the database for processing when the database supports that function. See MicroStrategy and Database Support for Functions for a list of the databases and the functions they support.

    When Randbetween is processed by a database, the real values can be used directly as input values without any rounding. For example, the expression Randbetween(0.5,1.6) for a metric will return a random, real number between the values of 0.5 and 1.6.

Example

Random numbers are used often in statistical analysis. A common practice is to apply a random percentage to another value. To do this, you can use the Randbetween function to return a number between 0 and 1. This can be achieved with the following syntax:

Randbetween(0, 1)

This returns a real number value between zero and one. This can be used in an expression to multiply against another value, which would return a random percentage of that value. For example, you can return a random percentage of revenue by creating a metric with the following definition:

(Sum(Revenue) {~+} * Randbetween(0, 1))

When using a metric with this definition on a report the same random percentage is applied to all revenue values on a report.

In the definition provided below, the metric Revenue is used in the Randbetween calculation. By including the revenue data as part of the calculation of Randbetween, a different random number is generated for each row of revenue data on a report.

Randbetween(0, Revenue)

These two metrics are created as Random Revenue 1 and Random Revenue 2 respectively, and displayed on the same report shown below:

Notice that the metric Random Revenue 2, which includes the revenue data as part of the Randbetween calculation, is using a different percentage for each row of revenue data. However, the metric Random Revenue 1 which uses a simple definition of the Randbetween calculation as Randbetween(0,1) uses the same random percentage to modify all rows of Revenue data.