github.com/blend/go-sdk@v1.20220411.3/uuid/v4.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package uuid 9 10 // crypto/rand here for correctness. 11 import "crypto/rand" 12 13 // V4 Create a new UUID version 4. 14 func V4() UUID { 15 var uuid UUID = Empty() 16 _, _ = rand.Read(uuid) 17 uuid[6] = (uuid[6] & 0x0f) | 0x40 // set version 4 18 uuid[8] = (uuid[8] & 0x3f) | 0x80 // set variant 2 19 return uuid 20 }