mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-11-09 03:37:37 -05:00
27 lines
504 B
Go
27 lines
504 B
Go
package protocol
|
|
|
|
import (
|
|
"math/rand"
|
|
)
|
|
|
|
type RandomTimestampGenerator interface {
|
|
Next() Timestamp
|
|
}
|
|
|
|
type RealRandomTimestampGenerator struct {
|
|
base Timestamp
|
|
delta int
|
|
}
|
|
|
|
func NewRandomTimestampGenerator(base Timestamp, delta int) RandomTimestampGenerator {
|
|
return &RealRandomTimestampGenerator{
|
|
base: base,
|
|
delta: delta,
|
|
}
|
|
}
|
|
|
|
func (this *RealRandomTimestampGenerator) Next() Timestamp {
|
|
rangeInDelta := rand.Intn(this.delta*2) - this.delta
|
|
return this.base + Timestamp(rangeInDelta)
|
|
}
|