Skip to content
/ grand Public

Golang random generator with simple entropy seeding

License

Notifications You must be signed in to change notification settings

Soreing/grand

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Random Generator

Build Coverage Go Report Card Go Reference

Grand is a simple random generator wrapper on math/rand seeded by entropy from crypto/rand

Usage

Create a source that can be used by the randomizer. NewSource creates a source with an optional seed. If there is no seed provided, a truly random seed will be derived from crypto/rand.

If a seed is provided, the function will not return an error. If entropy is used, the function can return an error if it fails to read bytes from crypto/rand

// New source using entropy
src, err := grand.NewSource()

// New source from existing seed
src, _ := grand.NewSource(1552664635341843643)

The randomizer can use any math/rand source, not only ones created using this package.

// New randomizer from source
rng := grand.New(src)