// NewUUID returns a new UUID.
429477
func NewUUID() (*UUID, error) {
	u := &UUID{}
	if _, err := rand.Read(u[:]); err != nil {
		return nil, err
	}
	u.setVariant(reservedRFC4122)
	u.setVersion(4)
	return u, nil
}
906749
func UUID() string {
	version := byte(4)
	uuid := make([]byte, 16)
	rand.Read(uuid)

	// Set version
	uuid[6] = (uuid[6] & 0x0f) | (version << 4)

	// Set variant
	uuid[8] = (uuid[8] & 0xbf) | 0x80

	buf := make([]byte, 36)
	var dash byte = '-'
	hex.Encode(buf[0:8], uuid[0:4])
	buf[8] = dash
	hex.Encode(buf[9:13], uuid[4:6])
	buf[13] = dash
	hex.Encode(buf[14:18], uuid[6:8])
	buf[18] = dash
	hex.Encode(buf[19:23], uuid[8:10])
	buf[23] = dash
	hex.Encode(buf[24:], uuid[10:])

	return string(buf)
}
505984
func NewNameBasedMD5(namespace, name string) (UUID, error) {
	u, err := md5.NewUUID(namespace, name)
	if err != nil {
		return Nil, err
	}

	uuid := UUID{}
	copy(uuid[:], u)

	return uuid, nil
}
469125
func SuffixUUID(suffix string, uuid string) (string, error) {
	uuidLetters := uuid[:8] + uuid[9:13] + uuid[14:18] + uuid[19:23] + uuid[24:36]
	uuidLetters = uuidLetters[:32-len(suffix)] + suffix
	suffixedUUID, err := FormatUUID(uuidLetters)
	if err != nil {
		return "", err
	}
	return suffixedUUID, nil
}
1030805
func NewV4() UUID {
	u := UUID{}
	safeRandom(u[:])
	u.SetVersion(4)
	u.SetVariant()

	return u
}
652229
func NewUUID() ([]byte, error) {
	// Get and release a global lock
	locker.Lock()
	defer locker.Unlock()

	uuid := make([]byte, 16)

	// get timestamp
	now := time.Now().UTC()
	timestamp := uint64(now.UnixNano()/100) + intervals // get timestamp
	if !now.After(lastGenerated) {
		clockSequence++ // last generated time known, then just increment clock sequence
	} else {
		b := make([]byte, 2)
		_, err := rand.Read(b)
		if err != nil {
			return nil, errors.Wrap(err, "could not generate clock sequence")
		}
		clockSequence = uint16(int(b[0])<<8 | int(b[1])) // set to a random value (network byte order)
	}

	lastGenerated = now // remember the last generated time

	timeLow := uint32(timestamp & 0xffffffff)
	timeMiddle := uint16((timestamp >> 32) & 0xffff)
	timeHigh := uint16((timestamp >> 48) & 0xfff)

	// network byte order(BigEndian)
	binary.BigEndian.PutUint32(uuid[0:], timeLow)
	binary.BigEndian.PutUint16(uuid[4:], timeMiddle)
	binary.BigEndian.PutUint16(uuid[6:], timeHigh)
	binary.BigEndian.PutUint16(uuid[8:], clockSequence)

	// get node id(mac address)
	if nodeID == nil {
		interfaces, err := net.Interfaces()
		if err != nil {
			return nil, errors.Wrap(err, "could not get network interfaces")
		}

		for _, i := range interfaces {
			if len(i.HardwareAddr) >= 6 {
				nodeID = make([]byte, 6)
				copy(nodeID, i.HardwareAddr)
				break
			}
		}

		if nodeID == nil {
			nodeID = make([]byte, 6)
			_, err := rand.Read(nodeID)
			if err != nil {
				return nil, errors.Wrap(err, "could not generate node id")
			}
		}
	}

	copy(uuid[10:], nodeID)

	// set version(v1)
	internal.SetVersion(uuid, internal.VersionTimeBased)
	// set layout(RFC4122)
	internal.SetLayout(uuid, internal.LayoutRFC4122)

	return uuid, nil
}
967782
func NewV2(domain byte) UUID {
	u := UUID{}

	timeNow, clockSeq, hardwareAddr := getStorage()

	switch domain {
	case DomainPerson:
		binary.BigEndian.PutUint32(u[0:], posixUID)
	case DomainGroup:
		binary.BigEndian.PutUint32(u[0:], posixGID)
	}

	binary.BigEndian.PutUint16(u[4:], uint16(timeNow>>32))
	binary.BigEndian.PutUint16(u[6:], uint16(timeNow>>48))
	binary.BigEndian.PutUint16(u[8:], clockSeq)
	u[9] = domain

	copy(u[10:], hardwareAddr)

	u.SetVersion(2)
	u.SetVariant()

	return u
}
1337275
func UUID16(i uint16) UUID {
	b := make([]byte, 2)
	binary.LittleEndian.PutUint16(b, i)
	return UUID{b}
}
1156194
func MustNewUUID() *UUID {
	uuid, err := NewUUID()
	if err != nil {
		panic(err)
	}
	return uuid
}
1223824
func (o *Generator) NewV5(namespace Implementation, names ...interface{}) UUID {
	id := UUID{}
	id.unmarshal(digest(sha1.New(), namespace.Bytes(), names...))
	id.setRFC4122Version(VersionFive)
	return id
}
155428
func NewV3(ns UUID, name string) UUID {
	return global.NewV3(ns, name)
}
92610
func NewV4() (u *UUID, err error) {
	u = new(UUID)
	// Set all bits to randomly (or pseudo-randomly) chosen values.
	_, err = rand.Read(u[:])
	if err != nil {
		return
	}
	u.setVariant(ReservedRFC4122)
	u.setVersion(4)
	return
}
466447
func uuidgen() string {
	b := uuidgenBytes()
	return fmt.Sprintf("%x-%x-%x-%x-%x",
		b[0:4], b[4:6], b[6:8], b[8:10], b[10:])
}
920558
func (c *ClusterManager) Uuid() string {
	if len(c.config.ClusterUuid) == 0 {
		return c.config.ClusterId
	}
	return c.config.ClusterUuid
}
1125045
func SetUUID(uuid string) ServerOption {
	return func(s *Server) error {
		s.uuid = uuid
		return nil
	}
}
1240478
func (o *Object) UUID() uuid.UUID {
	switch {
	case o.l != nil:
		return o.l.UUID()
	case o.p != nil:
		return o.p.UUID()
	default:
		return o.n.UUID()
	}
}
212577
func uuid() []byte {
	uuid := make([]byte, 16)
	_, err := rand.Read(uuid)
	if err != nil {
		panic("cue/hosted: uuid() failed to read random bytes")
	}

	// The following bit twiddling is outlined in RFC 4122.  In short, it
	// identifies the UUID as a v4 random UUID.
	uuid[6] = (4 << 4) | (0xf & uuid[6])
	uuid[8] = (8 << 4) | (0x3f & uuid[8])
	return uuid
}