Skip to main content
added 571 characters in body
Source Link
paparazzo
  • 6.1k
  • 3
  • 20
  • 43

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;
    }
}

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;
    }

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;
    }
}
deleted 1 character in body
Source Link
paparazzo
  • 6.1k
  • 3
  • 20
  • 43

don't new it every time
it is expensive and is not as random andas 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;
    }

don't new it every time
it is expensive and is not as random and 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;
    }

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;
    }
Source Link
paparazzo
  • 6.1k
  • 3
  • 20
  • 43

don't new it every time
it is expensive and is not as random and 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;
    }