Files
v2ray-core/proxy/vmess/protocol/rand.go
T
2016-02-25 16:40:43 +01:00

29 lines
597 B
Go

package protocol
import (
"math/rand"
"github.com/v2ray/v2ray-core/common/protocol"
)
type RandomTimestampGenerator interface {
Next() protocol.Timestamp
}
type RealRandomTimestampGenerator struct {
base protocol.Timestamp
delta int
}
func NewRandomTimestampGenerator(base protocol.Timestamp, delta int) RandomTimestampGenerator {
return &RealRandomTimestampGenerator{
base: base,
delta: delta,
}
}
func (this *RealRandomTimestampGenerator) Next() protocol.Timestamp {
rangeInDelta := rand.Intn(this.delta*2) - this.delta
return this.base + protocol.Timestamp(rangeInDelta)
}