Skip to content

Commit

Permalink
Merge pull request #203 from 9seconds/simplify-time-randomization
Browse files Browse the repository at this point in the history
Simplify TCP relay time randomization
  • Loading branch information
9seconds authored Aug 30, 2021
2 parents 00bb7be + ca5800c commit fbc7499
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions mtglib/internal/relay/timeouts.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package relay

import (
"math"
"math/rand"
"time"
)
Expand All @@ -15,12 +14,9 @@ func getTimeout() time.Duration {
}

func getTime(minDuration, maxDuration time.Duration) time.Duration {
minDurationInSeconds := minDuration.Seconds()
maxDurationInSeconds := maxDuration.Seconds()
middle := minDurationInSeconds + (maxDurationInSeconds-minDurationInSeconds)/2 // nolint: gomnd

number := minDurationInSeconds + rand.ExpFloat64()*middle
number = math.Round(math.Min(maxDurationInSeconds, number))
minDurationInSeconds := int(minDuration.Seconds())
maxDurationInSeconds := int(maxDuration.Seconds())
number := minDurationInSeconds + rand.Intn(maxDurationInSeconds-minDurationInSeconds)

return time.Duration(number) * time.Second
}

0 comments on commit fbc7499

Please sign in to comment.