tusd/uid/uid.go

24 lines
575 B
Go
Raw Permalink 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 {
// This is probably an appropiate way to handle errors from our source
// for random bits.
panic(err)
}
return hex.EncodeToString(id)
2013-03-17 15:42:47 +00:00
}