Crates.io | rand_simple |
lib.rs | rand_simple |
version | 0.2.32 |
source | src |
created_at | 2023-04-22 06:31:57.042176 |
updated_at | 2024-09-29 07:13:42.114265 |
description | The simple random number generator that is independent from the other libraries and based on XOR shift. |
homepage | |
repository | https://github.com/Tremendous1192/rand_simple |
max_upload_size | |
id | 845836 |
size | 165,676 |
rand_simple
is a Rust crate designed for efficient generation of pseudo-random numbers based on the Xorshift160 algorithm. It offers the following key features:
Xorshift160 Algorithm: rand_simple
leverages the proven Xorshift160 algorithm to create high-quality pseudo-random numbers.
Rich Variety of Probability Distributions: This crate aims to implement over 40 types of probability distribution random numbers, as featured in the book "Probability Distribution Random Number Generation Methods for Computer Simulation" by Tetsuaki Yotsuji(計算機シミュレーションのための確率分布乱数生成法/著者 四辻 哲章/プレアデス出版). These distributions cover a wide range of scenarios for computer simulations.
Convenient Use of Various Structs: With a simple declaration like use rand_simple::StructName;
, you gain access to a variety of structs for different probability distributions, making it easy to incorporate randomness into your applications.
If you are seeking an effective solution for random number generation in Rust, rand_simple
is a reliable choice. Start using it quickly and efficiently, taking advantage of its user-friendly features.
For graph-based examples, please refer to this repository.
// Generate a single seed value for initializing the random number generator
let seed: u32 = rand_simple::generate_seeds!(1_usize)[0];
// Create a new instance of the Uniform distribution with the generated seed
let mut uniform = rand_simple::Uniform::new(seed);
// Check the default range of the uniform distribution and print it
assert_eq!(format!("{uniform}"), "Range (Closed Interval): [0, 1]");
println!("Returns a random number -> {}", uniform.sample());
// When changing the parameters of the random variable
// Define new minimum and maximum values for the uniform distribution
let min: f64 = -1_f64;
let max: f64 = 1_f64;
// Attempt to set the new parameters for the uniform distribution
let result: Result<(f64, f64), &str> = uniform.try_set_params(min, max);
// Check the updated range of the uniform distribution and print it
assert_eq!(format!("{uniform}"), "Range (Closed Interval): [-1, 1]");
println!("Returns a random number -> {}", uniform.sample());
// Generate two seed values for initializing the random number generator
let seeds: [u32; 2_usize] = rand_simple::generate_seeds!(2_usize);
// Create a new instance of the Normal distribution with the generated seeds
let mut normal = rand_simple::Normal::new(seeds);
// Check the default parameters of the normal distribution (mean = 0, std deviation = 1) and print it
assert_eq!(format!("{normal}"), "N(Mean, Std^2) = N(0, 1^2)");
println!("Returns a random number -> {}", normal.sample());
// When changing the parameters of the random variable
// Define new mean and standard deviation values for the normal distribution
let mean: f64 = -3_f64;
let std: f64 = 2_f64;
// Attempt to set the new parameters for the normal distribution
let result: Result<(f64, f64), &str> = normal.try_set_params(mean, std);
// Check the updated parameters of the normal distribution and print it
assert_eq!(format!("{normal}"), "N(Mean, Std^2) = N(-3, 2^2)");
println!("Returns a random number -> {}", normal.sample());