Skip to content

Instantly share code, notes, and snippets.

@laixintao
Created December 24, 2021 02:58
Show Gist options
  • Save laixintao/a6c7f3f47eb06a81dcb57a780b6ccad0 to your computer and use it in GitHub Desktop.
Save laixintao/a6c7f3f47eb06a81dcb57a780b6ccad0 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
fmt.Printf("Generated service id: %s\n", CreateServiceID())
}
func CastUint64ToString(id uint64) (serviceID string) {
return fmt.Sprintf("%017x", id)
}
func CreateServiceID() string {
randnum := rand.Uint64() << 28
fmt.Println(randnum)
timestamp := uint64(time.Now().Unix()) & 0xfffffff
fmt.Println(timestamp)
num := (randnum) | (timestamp)
fmt.Println(num)
str := CastUint64ToString(num)
fmt.Println(str)
return str
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment