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.
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.
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?
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:
As you can see the i value is 10. so, we got an alphanumeric string which consists of 10 characters.
3 thoughts on “How to Generate Random AlphaNumeric string in UiPath”
Explanation is good. Useful to all.
Thank you, Srinivas