mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 01:54:02 +03:00
Simplify tcp relay time randomization
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package relay
|
package relay
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -15,12 +14,9 @@ func getTimeout() time.Duration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getTime(minDuration, maxDuration time.Duration) time.Duration {
|
func getTime(minDuration, maxDuration time.Duration) time.Duration {
|
||||||
minDurationInSeconds := minDuration.Seconds()
|
minDurationInSeconds := int(minDuration.Seconds())
|
||||||
maxDurationInSeconds := maxDuration.Seconds()
|
maxDurationInSeconds := int(maxDuration.Seconds())
|
||||||
middle := minDurationInSeconds + (maxDurationInSeconds-minDurationInSeconds)/2 // nolint: gomnd
|
number := minDurationInSeconds + rand.Intn(maxDurationInSeconds-minDurationInSeconds)
|
||||||
|
|
||||||
number := minDurationInSeconds + rand.ExpFloat64()*middle
|
|
||||||
number = math.Round(math.Min(maxDurationInSeconds, number))
|
|
||||||
|
|
||||||
return time.Duration(number) * time.Second
|
return time.Duration(number) * time.Second
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user