rand.go 504 B

1234567891011121314151617181920212223242526
  1. package protocol
  2. import (
  3. "math/rand"
  4. )
  5. type RandomTimestampGenerator interface {
  6. Next() Timestamp
  7. }
  8. type RealRandomTimestampGenerator struct {
  9. base Timestamp
  10. delta int
  11. }
  12. func NewRandomTimestampGenerator(base Timestamp, delta int) RandomTimestampGenerator {
  13. return &RealRandomTimestampGenerator{
  14. base: base,
  15. delta: delta,
  16. }
  17. }
  18. func (this *RealRandomTimestampGenerator) Next() Timestamp {
  19. rangeInDelta := rand.Intn(this.delta*2) - this.delta
  20. return this.base + Timestamp(rangeInDelta)
  21. }