package generate import ( "crypto/rand" "encoding/binary" "encoding/hex" "strings" "time" ) // ID generates a 24 character hex string from 8 bytes of current time // in ns and 4 bytes of crypto-random. In practical terms, that makes // them orderable. func ID() string { bytes := make([]byte, 12) binary.BigEndian.PutUint64(bytes, uint64(time.Now().UnixNano())) rand.Read(bytes[8:]) return strings.ToLower(hex.EncodeToString(bytes)) } // SessionID generates a 48 character hex string with crypto/rand func SessionID() string { bytes := make([]byte, 24) rand.Read(bytes) return strings.ToLower(hex.EncodeToString(bytes)) }