don't new it every time
it is expensive and is not as random as just keep using random
new Random() is based on a time seed
private Random rand = new Random();
protected override int Execute(CodeActivityContext context)
{
var min = context.GetValue(MinSeconds);
var max = context.GetValue(MaxSeconds);
var secondsToWait = rand.Next(min, max);
return secondsToWait;
}
OP said the many of the class are generated at once
Just create random once and pass it in the constructor
public class RandomSecondsGenerator
{
public int MinSeconds { get; set; }
public int MaxSeconds { get; set; }
private Random rand;
protected int Execute(DateTime context)
{
var secondsToWait = rand.Next(MinSeconds, MaxSeconds);
return secondsToWait;
}
public RandomSecondsGenerator(Random random)
{
rand = random;
}
}