new Random().Next() not working as expected

Hi Friends,

i need to select a value from a range of 1 to 5 randomly.

i tried below method

new Random().Next(1,5)

it works but the problem is randomly showing 1 to 4 only not 5.

could anyone helps me to solve this issue.

Thanks
Lenin KR

@Leninkraj,

As per the given values,

next(1,5), In VB or C# whatever it is, if you give the arguments as 1,5… then 1 will be included in the class and 5 is excluded. So, it will give from 1 and 2 and 3 and 4. So, if you want to include 5 as well, increase the second argument to 6. That will help

Let me know if it works

Hi
Welcome to uipath community
You were almost done
It should be like
new Random().Next(6)

Cheers @Leninkraj

Thank you very much Hareesh :slight_smile:

but is there any otherway becuase the second argument is coming from a variable of total count of row in a excel sheet.

Thanks in advance

Thanks Palani :slight_smile:

but the problem is “6” is parameter and is the total count of rows in a excelsheet

1 Like

Usually Random method has many overload with different number arguments it can take
For more information in that In detail this could help you

And the one u used is argument like
Random(min, max)
The one I mentioned is
Random(range) which will give any random number less than the mentioned one
Cheers @Leninkraj

1 Like

Then, while assigning, give it as variable + 1 @Leninkraj

1 Like