RandBetween

How to Use the Power Fx RandBetween  Function in Power Apps

Syntax of the RandBetween Function

The syntax of the RandBetween function in Power Apps is as follows:


RandBetween(min_value, max_value)


Where:

- `min_value` is the minimum value for the random number to be generated.

- `max_value` is the maximum value for the random number to be generated.

The RandBetween function generates a random number between the `min_value` and `max_value` values. Both `min_value` and `max_value` parameters are required.

Using the Power Fx RandBetween Function in Power Apps

The Power Fx RandBetween function can be used in various scenarios in Power Apps. For example, you can use it to generate random numbers for the following scenarios:

1. Creating a random password

2. Randomizing the order of list items

3. Generating random test data

Let's explore each of these scenarios in detail.

Creating a Random Password

In Power Apps, you can use the RandBetween function to create a random password. To do this, you will need to concatenate random characters with the RandBetween function. Here's an example formula that generates a random password with eight characters:


Concatenate(Char(RandBetween(65, 90)), Char(RandBetween(97, 122)), Char(RandBetween(48, 57)), Char(RandBetween(33, 47)))


This formula generates a random password that contains one uppercase letter, one lowercase letter, one number, and one special character.

Randomizing the Order of List Items

You can also use the RandBetween function to randomize the order of list items in Power Apps. To do this, you will need to use the SortByColumns function along with the RandBetween function. Here's an example formula that sorts a list called `MyList` in random order:


SortByColumns(MyList, RandBetween(1, 100))


This formula sorts the list `MyList` in a random order every time it is regenerated.

Generating Random Test Data

In Power Apps, you can use the RandBetween function to generate random test data. To do this, you will need to use the Collect function to collect the random data in a collection. Here's an example formula that generates a collection called `RandomData` with 10 random numbers between 1 and 100:


ClearCollect(RandomData, {

RandomNumber: RandBetween(1, 100)

}, {

RandomNumber: RandBetween(1, 100)

}, {

RandomNumber: RandBetween(1, 100)

}, {

RandomNumber: RandBetween(1, 100)

}, {

RandomNumber: RandBetween(1, 100)

}, {

RandomNumber: RandBetween(1, 100)

}, {

RandomNumber: RandBetween(1, 100)

}, {

RandomNumber: RandBetween(1, 100)

}, {

RandomNumber: RandBetween(1, 100)

}, {

RandomNumber: RandBetween(1, 100)

})


This formula generates a collection called `RandomData` with 10 random numbers between 1 and 100.

In conclusion, the Power Fx RandBetween function is a powerful tool for generating random numbers in Power Apps. It can be used in various scenarios, such as creating a random password, randomizing the order of list items, and generating random test data. By using the RandBetween function, you can make your Power Apps more dynamic and interactive.

Power Apps Training Courses by G Com Solutions (0800 998 9248)