Show background images in profile headers.
[bloat] / util / rand.go
1 package util
2
3 import (
4         "crypto/rand"
5         "math/big"
6 )
7
8 var (
9         runes        = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")
10         runes_length = len(runes)
11 )
12
13 func NewRandID(n int) (string, error) {
14         data := make([]rune, n)
15         for i := range data {
16                 num, err := rand.Int(rand.Reader, big.NewInt(int64(runes_length)))
17                 if err != nil {
18                         return "", err
19                 }
20                 data[i] = runes[num.Int64()]
21         }
22         return string(data), nil
23 }
24
25 func NewSessionID() (string, error) {
26         return NewRandID(24)
27 }
28
29 func NewCSRFToken() (string, error) {
30         return NewRandID(24)
31 }