Crates.io | vrd |
lib.rs | vrd |
version | 0.0.8 |
source | src |
created_at | 2023-02-05 22:56:40.532289 |
updated_at | 2024-08-27 16:08:06.3389 |
description | A Rust library for generating random and pseudo-random numbers based on the Mersenne Twister algorithm |
homepage | https://vrdlib.com |
repository | https://github.com/sebastienrousseau/vrd |
max_upload_size | |
id | 777491 |
size | 224,788 |
A Rust library for generating high-quality random numbers based on the Mersenne Twister algorithm.
• Website • Documentation • Report Bug • Request Feature • Contributing Guidelines
Random (VRD)
is a Rust library for generating high-quality random numbers based on the Mersenne Twister algorithm.
The Random
struct in this library provides a robust interface for generating a variety of random numbers using the Mersenne Twister algorithm. Additionally, the MersenneTwisterConfig
struct allows for advanced configuration of the algorithm.
Random (VRD)
generates pseudorandom integers uniformly distributed in 0..(2^32 - 1), starting from any odd seed in 0..(2^32 - 1). The index is incremented after each random number is generated. When the index reaches 624, the array is reinitialized and the index is reset to 0.
Add this to your Cargo.toml
:
[dependencies]
vrd = "0.0.8"
serde = { version = "1.0.209", features = ["derive"] }
Here's a quick example on how to use Random (VRD) to generate random numbers:
use vrd::random::Random;
let mut rng = Random::new();
let rand_int = rng.int(1, 10);
println!("Random integer between 1 and 10: {}", rand_int);
let rand_float = rng.float();
println!("Random float: {}", rand_float);
let rand_bytes = rng.bytes(10);
println!("Random bytes: {:?}", rand_bytes);
For full API documentation, please visit https://doc.libyml.com/vrd/ or https://docs.rs/vrd.
Compiler support: requires rustc 1.56.0+
Random (VRD)
provides a set of comprehensive examples. You can find them in the examples
directory of the project. To run the examples, clone the repository and execute the following command in your terminal from the project:
cargo run --example
The Random (VRD)
library provides a set of macros that simplify the usage of the library. These macros offer a convenient way to generate random numbers of different types and distributions.
Here are some of the available macros:
rand_bool!(rng, probability)
: Generate a random boolean with the provided probability.rand_bytes!(rng, length)
: Generate a vector of random bytes with the specified length.rand_char!(rng)
: Generate a random character within the range 'a'..='z'.rand_choose!(rng, values)
: Generate a random element from a slice of values.rand_float!(rng)
: Generate a random float.rand_int!(rng, min, max)
: Generate a random integer within the given range.rand_uint!(rng, min, max)
: Generate a random 32-bit unsigned integer within the given range.rand_double!(rng)
: Generate a random double.rand_string!(rng, length)
: Generate a random string of the specified length.rand_alphanumeric!(rng)
: Generate a random alphanumeric character.rand_shuffle!(rng, slice)
: Shuffle a mutable slice randomly.rand_weighted_choice!(rng, choices, weights)
: Select a random element from a slice based on the provided weights.rand_normal!(rng, mu, sigma)
: Generate a normally distributed random number with the given mean and standard deviation.rand_exponential!(rng, rate)
: Generate a random number from the exponential distribution with the given rate parameter.rand_poisson!(rng, mean)
: Generate a random number from a Poisson distribution with the specified mean parameter.For more details on how to use these macros, please refer to the documentation.
Contributions are welcome! Please submit a Pull Request on GitHub.
A big thank you to all the awesome contributors of vrd for their help and support.
A special thank you goes to the Rust Reddit community for providing a lot of useful suggestions on how to improve this project.
Licensed under either of the Apache License or the MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.