tusd/internal/uid/uid.go

24 lines
576 B
Go
Raw Normal View History

package uid
2013-03-17 15:42:47 +00:00
import (
"crypto/rand"
"encoding/hex"
2013-03-17 15:42:47 +00:00
"io"
)
// uid returns a unique id. These ids consist of 128 bits from a
// cryptographically strong pseudo-random generator and are like uuids, but
// without the dashes and significant bits.
//
// See: http://en.wikipedia.org/wiki/UUID#Random_UUID_probability_of_duplicates
func Uid() string {
2013-03-17 15:42:47 +00:00
id := make([]byte, 16)
_, err := io.ReadFull(rand.Reader, id)
if err != nil {
2016-09-27 20:10:16 +00:00
// This is probably an appropriate way to handle errors from our source
2013-03-17 15:42:47 +00:00
// for random bits.
panic(err)
}
return hex.EncodeToString(id)
2013-03-17 15:42:47 +00:00
}