How To Use The Power Apps RANDBETWEEN Function




Summary

The Power Apps RANDBETWEEN function generates a random whole number within a specific range. For example, we could ask for a random number between 1 and 10.



Syntax #1
RandBetween(Bottom, Top)


Arguments
NameRequired?Description
BottomYesA whole number that is the lowest number in the range
TopYesA whole number that is the highest number in the range



Examples

Suppose we want to generate a random number between 1 and 10. We could write the following Power Apps RANDBETWEEN function.

RandBetween(1, 10)



The result is a random number between 1 and 10. Each time the function is used it returns a different result. The 1st time I call the RANDBETWEEN function the result could be 3. Then the 2nd time I use RANDBETWEEN the result could be 7. The 3rd time I use the RANDBETWEEN function the result could be 1.

3
7
1




A challenge with the RANDBETWEEN function is the result always changes. If we wanted to keep the number generated by RANDBETWEEN for later we could store the result inside a variable.

Set(varRandomNumber, RandBetween(1, 10))


Subscribe
Notify of
guest
1 Comment
Oldest
Newest
Inline Feedbacks
View all comments
Robin
5 months ago

Love the formula, use it a lot to create Random demo data and used it to place the next target in my snake-game. Nice AddOn for fun Apps.

And you can choose a random item from a collection without Shuffle() now:
Index(Collection, RandBetween(1, CountRows(Collection))