Просмотр исходного кода

Simplify tcp relay time randomization

tags/v2.1.1
9seconds 4 лет назад
Родитель
Сommit
ca5800cf60
1 измененных файлов: 3 добавлений и 7 удалений
  1. 3
    7
      mtglib/internal/relay/timeouts.go

+ 3
- 7
mtglib/internal/relay/timeouts.go Просмотреть файл

1
 package relay
1
 package relay
2
 
2
 
3
 import (
3
 import (
4
-	"math"
5
 	"math/rand"
4
 	"math/rand"
6
 	"time"
5
 	"time"
7
 )
6
 )
15
 }
14
 }
16
 
15
 
17
 func getTime(minDuration, maxDuration time.Duration) time.Duration {
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
 	return time.Duration(number) * time.Second
21
 	return time.Duration(number) * time.Second
26
 }
22
 }

Загрузка…
Отмена
Сохранить