Skip to content

Set of utility functions for generating random data from crypto/rand

License

Notifications You must be signed in to change notification settings

theckman/go-securerandom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-securerandom

TravisCI Build Status :: theckman/go-securerandom GoDoc :: github.com/theckman/go-securerandom License

Package securerandom is a set of utilities for generating random data from the crypto/rand package. The package has the ability to generate bytes from secure-random data, as well as other data from those bytes. That includes numbers and Base64-encoded strings.

License

go-securerandom is released under the BSD 3-Clause License. See the LICENSE file for the full contents of the license.

Installation

go get -u github.com/theckman/go-securerandom

Usage

Full usage information can be found on the GoDoc page, but here is a short example:

import (
	"fmt"
	"math/rand"
	"github.com/theckman/go-securerandom"
)

ri64, err := securerandom.GenerateRandomInt64()

// secure-random data is unavailable
if err != nil {
	// handle err
}

rand.Seed(ri64)

You can also generate random base64 encoded strings from this package:

// generate string from 32 random bytes
rStr, err := securerandom.Base64OfBytes(32)

// secure-random data is unavailable
if err != nil { /* handle err */ }

fmt.Println(rStr)

// assume your random string can only be 32 bytes long
rStr, _ = securerandom.Base64InBytes(32)

fmt.Println(rStr) // would print Base64 string with a length of 32

About

Set of utility functions for generating random data from crypto/rand

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages