Random variable in for each loop not working properly


#1

Hello, I have a loop that runs through the rows of a table in which I generate a field with a random value - I use this instruction: new Random().Next(100000000,999999999).ToString.

The problem is that I have to include a delay of one second because otherwise the random is replicated in an average of ten rows until it changes.

With the delay it works fine but the processing time is more than an hour.

Any ideas?


#2

Hello.

How many rows do you have in the datatable and how do you specify the delay time?


#3

There are about 4K rows and I put the delay just after the assign instructions


#4

Do you need a number variable only?

If not, you can try Guid.NewGuid


#5

Just tried your scenario seems to be working if I instantiate Random outisde foreach

random = new Random()

row("id")= random.Next(100000000,999999999).ToString.

#6

Great vvaidya! Your solution is correct. It works when instantiating random outside foreach.
Thank you very much, you solve my problem!