For example, package main import ( "fmt" "math/rand" "time" ) func padWithRandomBytes(b []byte) []byte { s := 5 + rand.Intn(5+1) e := 5 + rand.Intn(5+1) slice := make([]byte, s+len(b)+e) copy(slice[s:], b) return slice } func main() { rand.Seed(time.Now().UnixNano()) b := []byte{1, 2, 3} fmt.Println(len(b), b) s := padWithRandomBytes(b) fmt.Println(len(s), s) } Output (random): 3 [1 2 3] 20 [0 0 0 0 0 0 0 0 1 2 3 0 0 0 0 0 0 0 0 0] 3 [1 2 3] 15 [0 0 0 0 0 0 1 2 3 0 0 0 0 0 0]