https://github.com/al-jshen/alea
Fast and easy zero-dep random number generation.
https://github.com/al-jshen/alea
Last synced: 2 months 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 (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-11-28T00:45:38.000Z (over 3 years ago)
- Last Synced: 2025-04-11T15:50:32.525Z (3 months ago)
- Language: Rust
- Homepage:
- Size: 47.9 KB
- Stars: 25
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# alea
[](https://crates.io/crates/alea)
[](https://docs.rs/alea)
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);
```