How to Generate Random AlphaNumeric string in UiPath

Generating a random alphanumeric string is mostly used when you are working with one time passwords.

In this article let us see how we can achieve that:

This is one way of doing this.

Firstly, we need to create a string variable that consists of alphabets and numbers as below:

Which will be used to generate random alphanumeric string.

uipath

If you want the small letters then include them as well in this string.

After this, we need to have a while condition where we are appending different characters into a string.

uipath

Where i is an integer value that will help us to set the length of the random alphanumeric string.

Create a StringBuilder variable which will help us to append the RANDOM values from constSTR as below.

After creating these two we have to create a variable of random type as below:

Now let’s see how we can append the values as string?

uipath

In the above image, we can see the expression used to append the values to create an alphanumeric string.

Now let’s understand how that is happening:

Firstly, constSTR.Length – giving the overall length of the constant string that we used earlier.

randomstr is a variable of random type, which will give us the random integer value in every iteration of i value reaching to 10(in this example).

Let’s say randomstr.Next(constSTR.Length) – given a random number 5.

Then constSTR(5) gives the value as F.

As mentioned above that is how it generates different characters by using random function.

Now for the last step, we will append each and every character that is generated in each iteration to stringBuilder variable.

The final output looks like below:

uipath message

As you can see the i value is 10. so, we got an alphanumeric string which consists of 10 characters.

Happy Learning!

Like this post then let your friends know about this-:

3 thoughts on “How to Generate Random AlphaNumeric string in UiPath

Leave a Reply

Your email address will not be published. Required fields are marked *