Browse Source

Merge pull request #203 from 9seconds/simplify-time-randomization

Simplify TCP relay time randomization
tags/v2.1.1
Sergey Arkhipov 4 years ago
parent
commit
fbc7499cda
No account linked to committer's email address
1 changed files with 3 additions and 7 deletions
  1. 3
    7
      mtglib/internal/relay/timeouts.go

+ 3
- 7
mtglib/internal/relay/timeouts.go View File

@@ -1,7 +1,6 @@
1 1
 package relay
2 2
 
3 3
 import (
4
-	"math"
5 4
 	"math/rand"
6 5
 	"time"
7 6
 )
@@ -15,12 +14,9 @@ func getTimeout() time.Duration {
15 14
 }
16 15
 
17 16
 func getTime(minDuration, maxDuration time.Duration) time.Duration {
18
-	minDurationInSeconds := minDuration.Seconds()
19
-	maxDurationInSeconds := maxDuration.Seconds()
20
-	middle := minDurationInSeconds + (maxDurationInSeconds-minDurationInSeconds)/2 // nolint: gomnd
21
-
22
-	number := minDurationInSeconds + rand.ExpFloat64()*middle
23
-	number = math.Round(math.Min(maxDurationInSeconds, number))
17
+	minDurationInSeconds := int(minDuration.Seconds())
18
+	maxDurationInSeconds := int(maxDuration.Seconds())
19
+	number := minDurationInSeconds + rand.Intn(maxDurationInSeconds-minDurationInSeconds)
24 20
 
25 21
 	return time.Duration(number) * time.Second
26 22
 }

Loading…
Cancel
Save