Core functionality for new aiterp.net servers
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
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)) }
|