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
|
|
|
}
|