Consul is a distributed, highly available, and data center aware solution to connect and configure applications across dynamic, distributed infrastructure.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
James Phillips bc2a45a9de
Updates memberlist and Serf (and adds new dependencies).
8 years ago
..
LICENSE Updates memberlist and Serf (and adds new dependencies). 8 years ago
README.md Updates memberlist and Serf (and adds new dependencies). 8 years ago
init.go Updates memberlist and Serf (and adds new dependencies). 8 years ago

README.md

seed - Quickly Seed Go's Random Number Generator

Boiler-plate to securely seed Go's random number generator (if possible). This library isn't anything fancy, it's just a canonical way of seeding Go's random number generator. Cribbed from Nomad before it was moved into Consul and made into a helper function, and now further modularized to be a super lightweight and reusable library.

Time is better than Go's default seed of 1, but friends don't let friends use time as a seed to a random number generator. Use seed.MustInit() instead.

seed.Init() is an idempotent and reentrant call that will return an error if it can't seed the value the first time it is called. Init() is reentrant.

seed.MustInit() is idempotent and reentrant call that will panic() if it can't seed the value the first time it is called. MustInit() is reentrant.

Usage

package mypackage

import (
  "github.com/sean-/seed"
)

// MustInit will panic() if it is unable to set a high-entropy random seed:
func init() {
  seed.MustInit()
}

// Or if you want to not panic() and can actually handle this error:
func init() {
  if ok, err := !seed.Init(); !ok {
    // Handle the error
    //panic(fmt.Sprintf("Unable to securely seed Go's RNG: %v", err))
  }
}