srand

🌱 Seed generator for srand (golang)

OTHER License

Stars
1
Committers
4

srand

😄 Initialize random seed in Golang.

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)