I use the code New random().Next(2,5) and I wanted to use the result of this code to delay activity so It shows the error as cannot convert String to Timespan

I am developing a code with 2 applications and want to run both the applications simultaneously , I want to generate some random time so I use the code
New random().Next(2,5) and I wanted to use the result of this code to delay activity so It shows the error as cannot convert String to Timespan
Help me with the solution

1 Like

welcome!

try this in delay activity. TimeSpan.FromSeconds(cdbl(new Random().Next(2,5))).ToString

randomFn.xaml (4.4 KB)

Thanks!

2 Likes

Word of advice -

In .NET Framework, which UiPath targets, best practice states that you should create a single Random instance that you reuse. If you create a new random for every operation, you run the risk of having two instances created with the same seed, which will result in the same values every time it’s run.

I would create a Random variable at the highest level that makes sense in your project, then consume that single instance as needed.

1 Like

Thank you