https://github.com/moul/srand
🌱 Seed generator for srand (golang)
https://github.com/moul/srand
golang prng random seed srand
Last synced: about 2 months ago
JSON representation
🌱 Seed generator for srand (golang)
- Host: GitHub
- URL: https://github.com/moul/srand
- Owner: moul
- License: other
- Created: 2020-02-23T06:55:40.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-11-16T08:49:38.000Z (7 months ago)
- Last Synced: 2025-04-15T11:12:57.498Z (about 2 months ago)
- Topics: golang, prng, random, seed, srand
- Language: Go
- Homepage: https://manfred.life/golang
- Size: 40 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE-APACHE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
- Authors: AUTHORS
Awesome Lists containing this project
README
# srand
:smile: Initialize random seed in Golang.
[](https://circleci.com/gh/moul/srand)
[](https://pkg.go.dev/moul.io/srand)
[](https://github.com/moul/srand/blob/master/COPYRIGHT)
[](https://github.com/moul/srand/releases)
[](https://goreportcard.com/report/moul.io/srand)
[](https://www.codefactor.io/repository/github/moul/srand)
[](https://codecov.io/gh/moul/srand)
[](https://golangci.com/r/github.com/moul/srand)
[](https://sourcegraph.com/github.com/moul/srand?badge)
[](https://manfred.life/)## Usage
```golang
import (
"math/rand"
"moul.io/srand"
)func init() {
rand.Seed(srand.MustSecure())
}
```Alternative seeds
```golang
// 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
```console
$ go get -u moul.io/srand
```## License
© 2019-2021 [Manfred Touron](https://manfred.life)
Licensed under the [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0) ([`LICENSE-APACHE`](LICENSE-APACHE)) or the [MIT license](https://opensource.org/licenses/MIT) ([`LICENSE-MIT`](LICENSE-MIT)), at your option. See the [`COPYRIGHT`](COPYRIGHT) file for more details.
`SPDX-License-Identifier: (Apache-2.0 OR MIT)`