blob: d8b9830be20002f4f3e7e8ef03d34a514dc00506 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
package uuid
import (
"crypto/rand"
"fmt"
"time"
)
// Generates a time ordered UUID. Top 32 bits are a timestamp,
// bottom 96 are random.
func TimeOrderedUUID() string {
unix := uint32(time.Now().UTC().Unix())
b := make([]byte, 12)
n, err := rand.Read(b)
if n != len(b) {
err = fmt.Errorf("Not enough entropy available")
}
if err != nil {
panic(err)
}
return fmt.Sprintf("%08x-%04x-%04x-%04x-%04x%08x",
unix, b[0:2], b[2:4], b[4:6], b[6:8], b[8:])
}
|