Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/moul/srand
🌱 Seed generator for srand (golang)
https://github.com/moul/srand
golang prng random seed srand
Last synced: 8 days 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 (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-11-16T08:49:38.000Z (about 2 months ago)
- Last Synced: 2024-12-05T14:51:00.442Z (29 days ago)
- Topics: golang, prng, random, seed, srand
- Language: Go
- Homepage: https://manfred.life/golang
- Size: 40 KB
- Stars: 1
- Watchers: 3
- 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.
[![CircleCI](https://circleci.com/gh/moul/srand.svg?style=shield)](https://circleci.com/gh/moul/srand)
[![GoDoc](https://img.shields.io/static/v1?label=godoc&message=reference&color=blue)](https://pkg.go.dev/moul.io/srand)
[![License](https://img.shields.io/badge/license-Apache--2.0%20%2F%20MIT-%2397ca00.svg)](https://github.com/moul/srand/blob/master/COPYRIGHT)
[![GitHub release](https://img.shields.io/github/release/moul/srand.svg)](https://github.com/moul/srand/releases)
[![Go Report Card](https://goreportcard.com/badge/moul.io/srand)](https://goreportcard.com/report/moul.io/srand)
[![CodeFactor](https://www.codefactor.io/repository/github/moul/srand/badge)](https://www.codefactor.io/repository/github/moul/srand)
[![codecov](https://codecov.io/gh/moul/srand/branch/master/graph/badge.svg)](https://codecov.io/gh/moul/srand)
[![GolangCI](https://golangci.com/badges/github.com/moul/srand.svg)](https://golangci.com/r/github.com/moul/srand)
[![Sourcegraph](https://sourcegraph.com/github.com/moul/srand/-/badge.svg)](https://sourcegraph.com/github.com/moul/srand?badge)
[![Made by Manfred Touron](https://img.shields.io/badge/made%20by-Manfred%20Touron-blue.svg?style=flat)](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)`