initial commits
parent
24be94455f
commit
8d6bd13393
|
@ -12,9 +12,14 @@ var (
|
||||||
func generate() uint64 {
|
func generate() uint64 {
|
||||||
|
|
||||||
var now int64 = time.Now().Unix()
|
var now int64 = time.Now().Unix()
|
||||||
|
return generateformoment(now)
|
||||||
|
}
|
||||||
|
|
||||||
|
func generateformoment(unixtimestamp int64) uint64 {
|
||||||
var chaos uint64 = randomness.Uint64()
|
var chaos uint64 = randomness.Uint64()
|
||||||
|
|
||||||
var value uint64 = compile(uint64(now), chaos)
|
var value uint64 = compile(uint64(unixtimestamp), chaos)
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
20
id.go
20
id.go
|
@ -49,6 +49,26 @@ func Generate() ID {
|
||||||
return something(value)
|
return something(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GenerateForMoment returns a new xim-id that has embedded in it the time given by the unix-timestamp in the variable ‘unixtimestamp’.
|
||||||
|
//
|
||||||
|
// Example usage:
|
||||||
|
//
|
||||||
|
// var unixTimeStamp int32 = 1636403305 // I.e., Monday, November 8, 2021 12:28:25 PM GMT-08:00
|
||||||
|
//
|
||||||
|
// var id xim.ID = xim.GenerateForMoment(unixTimeStamp)
|
||||||
|
//
|
||||||
|
// fmt.Println("xim-id =", id)
|
||||||
|
//
|
||||||
|
// The chaos part of this xim-id will be chosen randomly (just like with xim.Generate()).
|
||||||
|
func GenerateForMoment(unixtimestamp int32) ID {
|
||||||
|
|
||||||
|
var when int64 = int64(unixtimestamp)
|
||||||
|
|
||||||
|
var value uint64 = generateformoment(when)
|
||||||
|
|
||||||
|
return something(value)
|
||||||
|
}
|
||||||
|
|
||||||
// Chaos returns the randomness that is embeddd in the xim-id.
|
// Chaos returns the randomness that is embeddd in the xim-id.
|
||||||
//
|
//
|
||||||
// Example usage:
|
// Example usage:
|
||||||
|
|
Loading…
Reference in New Issue