Welcome to mirror list, hosted at ThFree Co, Russian Federation.

random.go « text « helper « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3f5641660561772e01c533b38f451be02706ad08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package text

import (
	"crypto/rand"
	"encoding/hex"
	"io"
)

// RandomHex returns an n-byte hexadecimal random string.
func RandomHex(n int) (string, error) {
	buf := make([]byte, n)
	if _, err := io.ReadFull(rand.Reader, buf); err != nil {
		return "", err
	}

	return hex.EncodeToString(buf), nil
}