| 1 |
// Copyright 2011 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. |
| 4 |
|
| 5 |
package uuid |
| 6 |
|
| 7 |
import guuid "github.com/google/uuid" |
| 8 |
|
| 9 |
// Random returns a Random (Version 4) UUID or panics. |
| 10 |
// |
| 11 |
// The strength of the UUIDs is based on the strength of the crypto/rand |
| 12 |
// package. |
| 13 |
// |
| 14 |
// A note about uniqueness derived from the UUID Wikipedia entry: |
| 15 |
// |
| 16 |
// Randomly generated UUIDs have 122 random bits. One's annual risk of being |
| 17 |
// hit by a meteorite is estimated to be one chance in 17 billion, that |
| 18 |
// means the probability is about 0.00000000006 (6 × 10−11), |
| 19 |
// equivalent to the odds of creating a few tens of trillions of UUIDs in a |
| 20 |
// year and having one duplicate. |
| 21 |
func NewRandom() UUID { |
| 22 |
if gu, err := guuid.NewRandom(); err == nil { |
| 23 |
return UUID(gu[:]) |
| 24 |
} |
| 25 |
return nil |
| 26 |
} |