mirror of https://github.com/smol-rs/fastrand
76cd760762 | ||
---|---|---|
examples | ||
src | ||
.gitignore | ||
CHANGELOG.md | ||
Cargo.toml | ||
LICENSE-APACHE | ||
LICENSE-MIT | ||
README.md |
README.md
fastrand
A simple random number generator.
Easy to use but not cryptographically secure.
Examples
Flip a coin:
if fastrand::bool() {
println!("heads");
} else {
println!("tails");
}
Generate a random i32
:
let num = fastrand::i32(..);
Choose a random element in an array:
let v = vec![1, 2, 3, 4, 5];
let i = fastrand::usize(..v.len());
let elem = v[i];
Shuffle an array:
let mut v = vec![1, 2, 3, 4, 5];
fastrand::shuffle(&mut v);
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.