1 // Copyright 2016 Google Inc. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
9 // New creates a new random UUID or panics. New is equivalent to
12 // uuid.Must(uuid.NewRandom())
14 return Must(NewRandom())
17 // NewRandom returns a Random (Version 4) UUID.
19 // The strength of the UUIDs is based on the strength of the crypto/rand
22 // A note about uniqueness derived from the UUID Wikipedia entry:
24 // Randomly generated UUIDs have 122 random bits. One's annual risk of being
25 // hit by a meteorite is estimated to be one chance in 17 billion, that
26 // means the probability is about 0.00000000006 (6 × 10−11),
27 // equivalent to the odds of creating a few tens of trillions of UUIDs in a
28 // year and having one duplicate.
29 func NewRandom() (UUID, error) {
31 _, err := io.ReadFull(rander, uuid[:])
35 uuid[6] = (uuid[6] & 0x0f) | 0x40 // Version 4
36 uuid[8] = (uuid[8] & 0x3f) | 0x80 // Variant is 10