Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/al-jshen/alea
Fast and easy zero-dep random number generation.
https://github.com/al-jshen/alea
Last synced: about 1 month ago
JSON representation
Fast and easy zero-dep random number generation.
- Host: GitHub
- URL: https://github.com/al-jshen/alea
- Owner: al-jshen
- License: apache-2.0
- Created: 2021-07-16T16:34:51.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-11-28T00:45:38.000Z (about 3 years ago)
- Last Synced: 2024-11-09T07:12:02.105Z (about 1 month ago)
- Language: Rust
- Homepage:
- Size: 47.9 KB
- Stars: 25
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# alea
[![Crates.io](https://img.shields.io/crates/v/alea.svg?style=for-the-badge&color=fc8d62&logo=rust)](https://crates.io/crates/alea)
[![Documentation](https://img.shields.io/badge/docs.rs-alea-5E81AC?style=for-the-badge&labelColor=555555&logoColor=white)](https://docs.rs/alea)
![License](https://img.shields.io/crates/l/alea?label=License&style=for-the-badge&color=62a69b)A zero-dependency crate for fast number generation, with a focus on ease of use (no more passing `&mut rng` everywhere!).
The implementation is based on [wyrand](https://github.com/wangyi-fudan/wyhash), a high-quality and fast generator.
This crate is heavily inspired by [fastrand](https://github.com/smol-rs/fastrand). For some benchmarks, see [benches](benches).
## Usage
Add the following to your `Cargo.toml`:
```rust
[dependencies]
alea = "0.2"
```## Examples
Flip a coin:
```rust
if alea::bool() {
println!("heads");
} else {
println!("tails");
}
```Generate a `u64`:
```rust
let u = alea::u64();
```Fill a vector with random integers in some range:
```rust
let n = 1_000_000;let mut v = vec![0; n];
for i in 0..n {
v[i] = alea::i32_in_range(-200, 150);
}
```Seed the generator to get reproducible results:
```rust
alea::set_seed(10);
```