ID/generator.go

26 lines
370 B
Go

package ID
import "math/rand"
const MaxID = 2 << 24
type Type uint
type Generator struct {
// IDEA: i hate you
step Type
Last Type
}
func (idg *Generator) Next() Type {
idg.Last = (idg.Last + idg.step) % MaxID
return idg.Last
}
func New(seed uint32) *Generator {
return &Generator{
Last: Type(seed % MaxID),
step: Type((rand.Uint32() % MaxID) | 1),
}
}