You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ntool/nrandom/bytes.go

21 lines
285 B
Go

package nrandom
import (
crand "crypto/rand"
"io"
)
// RandBytes generate random byte slice.
func RandBytes(length int) []byte {
if length < 1 {
return []byte{}
}
b := make([]byte, length)
if _, err := io.ReadFull(crand.Reader, b); err != nil {
return nil
}
return b
}