-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbytes.go
33 lines (25 loc) · 1002 Bytes
/
bytes.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
27
28
29
30
31
32
33
/*
Package gorand defines a set of utility methods to work with random data.
The main goal is to curate a collection of functions for random data generation
in different formats to be used for different purposes.
It uses the "crypto/rand" package to provide the most secure random data,
unless indicated otherwise where performance can be the main focus of the method.
Most implementations are really trivial and anybody could write the same on their own packages,
but here we can centralize all of them and keep a unified way of retrieving random data.
Unified QA is another motivator to have and use this package.
*/
package gorand
import (
"crypto/rand"
)
// GetBytes returns a fixed amount of random bytes.
// Specify the amount of bytes wanted by passing it on the n parameter.
// This function is the base for most of the methods on this package.
func GetBytes(n int) ([]byte, error) {
b := make([]byte, n)
_, err := rand.Read(b)
if err != nil {
return nil, err
}
return b, nil
}