Skip to content
/ srand Public
generated from moul/golang-repo-template

🌱 Seed generator for srand (golang)

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

moul/srand

srand

πŸ˜„ Initialize random seed in Golang.

CircleCI GoDoc License GitHub release Go Report Card CodeFactor codecov GolangCI Sourcegraph Made by Manfred Touron

Usage

import (
    "math/rand"
    "moul.io/srand"
)

func init() {
    rand.Seed(srand.MustSecure())
}

Alternative seeds

// simple seed initializer
rand.Seed(srand.Fast())

// thread-safe simple seed initializer
go func() { rng := rand.New(rand.NewSource(srand.SafeFast())); fmt.Println(rng.Intn(42)) }()
go func() { rng := rand.New(rand.NewSource(srand.SafeFast())); fmt.Println(rng.Intn(42)) }()

// simple seed initializer overridable by the $SRAND env var
rand.Seed(srand.Overridable("SRAND"))

// cryptographically secure initializer
rand.Seed(srand.MustSecure())

Install

$ go get -u moul.io/srand

License

Β© 2019-2021 Manfred Touron

Licensed under the Apache License, Version 2.0 (LICENSE-APACHE) or the MIT license (LICENSE-MIT), at your option. See the COPYRIGHT file for more details.

SPDX-License-Identifier: (Apache-2.0 OR MIT)