Add Uuid.randV4

This commit is contained in:
jaina heartles 2022-05-12 20:27:42 -07:00
parent c484af6179
commit b140b20298
1 changed files with 11 additions and 0 deletions

View File

@ -55,6 +55,17 @@ pub const Uuid = struct {
return uuid;
}
pub fn randV4(rand: std.rand.Random) Uuid {
var ret: Uuid = undefined;
rand.bytes(&ret.data);
// signify that this is a random v4 uuid
ret.data[7] = (0b0100_0000) | (ret.data[7] & 0b1111);
ret.data[9] = (0b1000_0000) | (ret.data[9] & 0b11_1111);
return ret;
}
};
pub const ciutf8 = struct {