Skip to content

Random Data

Prajwal Koirala edited this page Jul 4, 2021 · 3 revisions
package main

import (
        "crypto/rand"
        "fmt"
        "os"
)

func main() {
        os.WriteFile("random-test-file", []byte(randomString(256)), 0644)
}

func randomString(bytesize int) string {
        randomBytes := make([]byte, bytesize)
        rand.Read(randomBytes)
        randomString := fmt.Sprintf("%X", randomBytes)
        return randomString
}
Clone this wiki locally