This repository contains a collection of random number generators (RNGs) implemented in Go, designed to cater to a wide range of applications, from cryptographic operations to testing environments. Each RNG in the collection offers distinct features and performance characteristics, making it suitable for various use cases, including those requiring cryptographic security.
- Description: Utilizes Go's
crypto/rand
package to provide cryptographically secure random numbers, suitable for security-sensitive applications. - Usage:
source := NewCryptoSource() number := source.Uint64()
- Description: An implementation of the Jenkins Small Fast hash function for efficient pseudo-random number generation, balancing speed and randomness quality for general use.
- Usage:
source := NewJSFSource(seed) number := source.Uint64()
- Description: Based on the Simple Fast Counter algorithm, this source offers rapid number generation with satisfactory randomness properties, ideal for simulations and non-cryptographic applications.
- Usage:
source := NewSFCSource(seed) number := source.Uint64()
- Description: A deterministic generator designed primarily for testing, providing predictable output for scenarios where consistent results are more beneficial than high-quality randomness.
- Usage:
source := NewDumb(seed) number := source.Uint64()
To use these RNGs in your Go project, import the package as follows:
import "github.com/yourusername/randsource"
Replace yourusername
with your GitHub username or organization name where the repository is hosted.
After importing the package, initialize the desired RNG with or without a seed (as applicable) and use the Uint64
method to generate random numbers. See the usage examples under each generator's description for more details.
Performance benchmarks for each RNG are provided to help you choose the right generator for your application. These benchmarks cover various aspects, including speed and randomness quality.
For detailed benchmark results, see the Benchmarks file.
We welcome contributions and suggestions! Please open an issue or submit a pull request with your improvements.