-
Notifications
You must be signed in to change notification settings - Fork 35
/
id.go
26 lines (23 loc) · 635 Bytes
/
id.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http:https://mozilla.org/MPL/2.0/.
//
// Contributor: Julien Vehent [email protected] [:ulfr]
package main
import (
"crypto/rand"
"math/big"
"strconv"
)
// id returns a 128bits random id encoded in base36
func id() string {
b := make([]byte, 16)
_, err := rand.Read(b)
if err != nil {
panic(err)
}
x, y := new(big.Int), new(big.Int)
x.SetBytes(b[:8])
y.SetBytes(b[8:])
return strconv.FormatUint(x.Uint64(), 36) + strconv.FormatUint(y.Uint64(), 36)
}