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

rand: add rand.ulid_at_millisecond/1, use it in rand.ulid/0

This commit is contained in:
Delyan Angelov
2020-07-26 14:09:49 +03:00
parent 7d52d612ce
commit dfa01d8877
2 changed files with 11 additions and 17 deletions

View File

@ -5,7 +5,6 @@ module rand
import rand.util
import rand.wyrand
import time
// Configuration struct for creating a new instance of the default RNG.
@ -196,10 +195,13 @@ const(
// users or business transactions.
// (https://news.ycombinator.com/item?id=14526173)
pub fn ulid() string {
return ulid_at_millisecond(time.utc().unix_time_milli())
}
pub fn ulid_at_millisecond(unix_time_milli u64) string {
buflen := 26
mut buf := malloc(27)
// time section
mut t := time.utc().unix_time_milli()
mut t := unix_time_milli
mut i := 9
for i >= 0 {
unsafe{
@ -230,5 +232,5 @@ pub fn ulid() string {
unsafe{
buf[26] = 0
}
return string(buf,buflen)
return string(buf, buflen)
}