Rand Creates the Same Random Number Over and Over Again
This browser is no longer supported.
Upgrade to Microsoft Edge to have advantage of the latest features, security updates, and technical support.
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
-
Add a Slider command, and rename information technology Slider1 if it has a different name.
-
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:
-
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:
Create a tabular array of random numbers
-
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.
-
Add together a Information table, fix its Items property to RandomNumbers, and testify the Value field.
-
While property down the Alt key, select the button by clicking or tapping information technology.
The data table shows 5 random decimal numbers:
-
Select the button again to testify a different list of random numbers:
To generate a single random number instead of a table, utilise Set( RandomNumber, Rand() ).
Feedback
Submit and view feedback for
Source: https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-rand