Generate a random number
Power Automate Desktop offers a wide range of actions for retrieving data from web pages and on-premises software.
In many cases, you can search for an action and do what you want just by dragging and dropping it.
This article explains how to generate a different random number on each run, with a specified minimum and maximum value.
You can also generate multiple numbers at once as a list.
Generating a single random number
Section titled “Generating a single random number”Implement by copying and pasting
Section titled “Implement by copying and pasting”Copy the following code and paste it into the Power Automate Desktop flow designer to add the action.
Variables.GenerateRandomNumber.RandomNumber MinimumValue: 0 MaximumValue: 100 RandomNumber=> RandomNumberImplement in Power Automate Desktop
Section titled “Implement in Power Automate Desktop”In “Search actions”, type “Generate random number”.
Set the lower and upper limits of the random value you want in “Minimum value” and “Maximum value”, and a random number is generated each time the flow runs (the defaults are a minimum of 0 and a maximum of 100).
Generating multiple random numbers at once as a list
Section titled “Generating multiple random numbers at once as a list”Implement by copying and pasting
Section titled “Implement by copying and pasting”Copy the following code and paste it into the Power Automate Desktop flow designer to add the action.
Variables.GenerateRandomNumber.ListOfRandomNumbers MinimumValue: 0 MaximumValue: 100 NumbersCount: 10 AllowDuplicates: False RandomNumbers=> RandomNumbersImplement in Power Automate Desktop
Section titled “Implement in Power Automate Desktop”- In “Search actions”, type “Generate random number”.
- Turn on “Generate multiple numbers”, and you can set how many numbers to generate at once.
- If you don’t want the same number to appear more than once, leave “Allow duplicates” turned off (
AllowDuplicates: Falsein the code). In this case, the random numbers can’t be generated if the number you ask for is larger than the count of distinct numbers available between the minimum and maximum values. - As with a single number, set the lower and upper limits of the random values you want, and a list of random numbers is generated each time the flow runs.