27 lines
500 B
Go
Raw Normal View History

2015-09-20 00:11:14 +02:00
package user
2015-09-16 21:13:13 +02:00
import (
"math/rand"
)
2016-01-12 11:38:43 +01: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 21:13:13 +02:00
2016-01-12 11:38:43 +01:00
func (this *RealRandomTimestampGenerator) Next() Timestamp {
rangeInDelta := rand.Intn(this.delta*2) - this.delta
return this.base + Timestamp(rangeInDelta)
2015-09-16 21:13:13 +02:00
}