1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-09 11:51:02 -05:00
v2fly/proxy/vmess/protocol/rand.go

27 lines
504 B
Go
Raw Normal View History

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