Crate vrd

source Â·
Expand description

Â§`Random (VRD)` ðŸ¦€

A Rust library for generating high-quality random numbers based on the Mersenne Twister algorithm.

Part of the Mini Functions family of libraries.

Â§Overview

The Mersenne Twister is a pseudorandom number generator (PRNG) that is often used in computer simulations and games. It is a fast and reliable PRNG.

`Random (VRD)` can be used to generate random numbers based on the Mersenne Twister algorithm. The library 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.

Â§Features âœ¨

• Create new random number generator and seed it with a value.
• Design for speed and efficiency in mind.
• Generate random 32-bit unsigned integer within a given range.
• Provide random numbers of different types, including booleans, bytes, chars, doubles, floats, integers, and unsigned integers.
• Mutate the state of the random number generator.
• Produce pseudo-random number sequences that are different from each other.
• Regulate the randomness of the generated numbers, including the seed value and the number of bits used.
• Select a random element from a slice of values.

Â§Usage

Add the following to your `Cargo.toml` file:

``````[dependencies]
vrd = "0.0.7"
serde = { version = "1.0.160", features = ["derive"] }
``````

Â§Examples

Check out the examples folder for helpful snippets of code that demonstrate how to use the `Random (VRD)` library. You can also check out the documentation for more information on how to use the library.

``````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);
``````

Â§Errors

The `Random` struct methods do not currently return errors, but in the future they may return `Result` types to handle situations where the Mersenne Twister algorithm fails to generate a random number or a range of numbers.

Re-exportsÂ§

• `pub use mersenne_twister::MersenneTwisterConfig;`

ModulesÂ§

• The `macros` module contains functions for generating macros.
• The `mersenne_twister` module contains the implementation of the Mersenne Twister algorithm.
• The `random` module contains the implementation of the `Random` struct.

MacrosÂ§

• Generates a random alphanumeric character (a-z, A-Z, 0-9).
• Generate a random boolean with a provided probability.
• Generate a vector of random bytes with the provided length using the provided `Random (VRD)` struct
• Generate a random char within the range â€˜aâ€™..=â€˜zâ€™ using the provided `Random (VRD)` struct
• Generate a random element from a slice of values using the provided `Random (VRD)` struct
• Generate a random double using the provided `Random (VRD)` struct
• Generate a random number from the exponential distribution with the given rate parameter.
• Generate a random float using the provided `Random (VRD)` struct
• Generate a random integer within the given range using the provided `Random (VRD)` struct
• Generate a new random number
• Generate a normally distributed random number with the given mean and standard deviation.
• Generates a random number from a Poisson distribution with the specified mean parameter.
• Generate a random 32-bit unsigned integer using the provided `Random (VRD)` struct
• Generate a random number within the given range using the provided `Random (VRD)` struct
• Seed the provided `Random (VRD)` struct with the given value
• Shuffles a mutable slice randomly.
• Generates a random string of the specified length.
• Twist the state of the provided `Random (VRD)` struct
• Generate a random 32-bit unsigned integer within the given range using the provided `Random (VRD)` struct
• Selects a random element from a slice based on the provided weights.
• Generate a random 32-bit unsigned integer within the given range using the provided `Random (VRD)` struct