Skip to main content
3 of 3
deleted 12 characters in body
peterSO
  • 3.5k
  • 13
  • 14

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)
    r := make([]byte, s+len(b)+e)
    copy(r[s:], b)
    return r
}

func main() {
    rand.Seed(time.Now().UnixNano())
    b := []byte{1, 2, 3}
    fmt.Println(len(b), b)
    r := padWithRandomBytes(b)
    fmt.Println(len(r), r)
}

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]
peterSO
  • 3.5k
  • 13
  • 14