version4.go 863 B

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