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:
@@ -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
|
||||
|
Reference in New Issue
Block a user