1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

rand: use time microseconds too in default rand initialization; generate proper uuid_v4

This commit is contained in:
Delyan Angelov
2020-07-24 14:28:27 +03:00
parent c429fa7e27
commit 289974dd15
4 changed files with 17 additions and 5 deletions

View File

@@ -149,13 +149,18 @@ pub fn string(len int) string {
pub fn uuid_v4() string {
mut buf := malloc(37)
for i in 0..36 {
mut v := intn(16)
if i == 19 {
v = (v & 0x3) | 0x8
}
unsafe {
buf[i] = hex_chars[intn(16)]
buf[i] = hex_chars[v]
}
}
unsafe {
buf[8] = `-`
buf[13] = `-`
buf[14] = `4`
buf[18] = `-`
buf[23] = `-`
buf[36] = 0