pkg/libcontainer/utils/utils.go

18 lines
422 B
Go
Raw Normal View History

package utils
import (
"crypto/rand"
"encoding/hex"
"io"
)
// GenerateRandomName returns a new name joined with a prefix. This size
// specified is used to truncate the randomly generated value
func GenerateRandomName(prefix string, size int) (string, error) {
id := make([]byte, 32)
if _, err := io.ReadFull(rand.Reader, id); err != nil {
return "", err
}
return prefix + hex.EncodeToString(id)[:size], nil
}