v2ray-core/proxy/vmess/protocol/rand.go

27 lines
504 B
Go
Raw Normal View History

2016-01-12 10:52:40 +00:00
package protocol
2015-09-16 19:13:13 +00:00
import (
"math/rand"
)
2016-01-12 10:38:43 +00:00
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,
}
}
2015-09-16 19:13:13 +00:00
2016-01-12 10:38:43 +00:00
func (this *RealRandomTimestampGenerator) Next() Timestamp {
rangeInDelta := rand.Intn(this.delta*2) - this.delta
return this.base + Timestamp(rangeInDelta)
2015-09-16 19:13:13 +00:00
}