Rand function in Power Apps

Returns a pseudo-random number.

Description

The Rand office returns a pseudo-random number that's greater than or equal to 0 and less than 1.

Volatile Functions

Rand is a volatile role. Each time the function is evaluated it returns a dissimilar value.

When used in a information catamenia formula, a volatile function will only return a dissimilar value if the formula in which it appears is reevaluated. If cipher else changes in the formula then it will take the same value throughout the execution of your app.

For example, a label command with Label1.Text = Rand() will not change while your app is agile. Only closing and reopening the app will upshot in a new value.

The function will exist reevaluated if it is part of a formula in which something else has changed. For example, if we alter our example to involve a slider control with Label1.Text = Slider1.Value + Rand() so a new random number is generated each time the Slider control's value changes and the label's text belongings is reevaluated. Encounter beneath for this instance.

When used in a behavior formula, Rand volition be evaluated each time the beliefs formula is evaluated. Encounter beneath for an case.

Syntax

Rand()

Examples

Display a dissimilar random number every bit user input changes

  1. Add a Slider command, and rename information technology Slider1 if it has a different name.

  2. Add a Label command, and gear up its Text belongings to this formula:

    Slider1.Value + Rand()

    The label shows fifty (the default value for the slider) plus a random decimal:

    A screen displaying a label control with 50.741.

  3. While property down the Alt primal, change the value of the slider.

    Every time you change the value of the slider, the decimal portion of the label shows a different random number:

    Four screens displaying a label control with four different random decimal values for each of four different slider settings 70.899, 84.667, 90.134, 99.690.

Create a tabular array of random numbers

  1. Add together a Push control, and set its OnSelect property to this formula:

    ClearCollect( RandomNumbers, ForAll( [ ane, 2, 3, iv, 5 ], Rand() ))

    This formula creates a unmarried-column table that's used to iterate 5 times, resulting in v random numbers.

  2. Add together a Information table, fix its Items property to RandomNumbers, and testify the Value field.

    A screen showing a data table with five different decimal values 0.857, 0.105, 0.979, 0.167, 0.814.

  3. While property down the Alt key, select the button by clicking or tapping information technology.

    The data table shows 5 random decimal numbers:

    Data table with five decimal numbers.

  4. Select the button again to testify a different list of random numbers:

    The same screen showing a data table with a new set of five different decimal values 0.414, 0.128, 0.860, 0.303, 0.568.

To generate a single random number instead of a table, utilise Set( RandomNumber, Rand() ).