Need to generate a set of random bytes?

package main

import (

func GenRandomBytes(size int) (blk []byte, err error) {
    blk = make([]byte, size)
    _, err = rand.Read(blk)

func main() {
    if blk, err := GenRandomBytes(32); err != nil {
    } else {
        sblk := string(blk)
        fmt.Printf("sblk: %s\n", sblk)
        fmt.Printf("hex : %x\n", blk)

Categories: Code


Ideals are like the stars: we never reach them, but like the mariners of the sea, we chart our course by them.

Leave a Reply

Your email address will not be published. Required fields are marked *