blob: 172ed90c43a5199693408cd23386aaf3aae37645 (
plain) (
blame)
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 main
import (
"crypto/rand"
"encoding/base64"
)
func e(e error) {
if e != nil {
panic(e)
}
}
/*
* Generate a random url-safe string.
* Note that the "len" parameter specifies the number of bytes taken from the
* random source divided by three and does NOT represent the length of the
* encoded string.
*/
func random(len int) string {
r := make([]byte, 3*len)
rand.Read(r)
return base64.RawURLEncoding.EncodeToString(r)
}
|