## rand_simple

The simple random number generator that is independent from the other libraries and based on XOR shift

### 78 releases

 new 0.2.30 Jul 7, 2024 May 10, 2024 Mar 23, 2024 Dec 29, 2023 Jul 28, 2023

#222 in Algorithms

MIT/Apache

145KB
2K SLoC

# rand_simple

`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:

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.

## Usage Examples

For graph-based examples, please refer to this repository.

### Uniform Distribution

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

``````

### Normal Distribution

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

``````

## Implementation Status

### Continuous distribution

• Uniform distribution
• 3.1 Normal distribution
• 3.2 Half Normal distribution
• 3.3 Log-Normal distribution
• 3.4 Cauchy distribution
• Half-Cauchy distribution
• 3.5 Lévy distribution
• 3.6 Exponential distribution
• 3.7 Laplace distribution
• Log-Laplace distribution
• 3.8 Rayleigh distribution
• 3.9 Weibull distribution
• Reflected Weibull distribution
• Fréchet distribution
• 3.10 Gumbel distribution
• 3.11 Gamma distribution
• 3.12 Beta distribution
• 3.13 Dirichlet distribution
• 3.14 Power Function distribution
• 3.15 Exponential Power distribution
• Half Exponential Power distribution
• 3.16 Erlang distribution
• 3.17 Chi-Square distribution
• 3.18 Chi distribution
• 3.19 F distribution
• 3.20 t distribution
• 3.21 Inverse Gaussian distribution
• 3.22 Triangular distribution
• 3.23 Pareto distribution
• 3.24 Logistic distribution
• 3.25 Hyperbolic Secant distribution
• 3.26 Raised Cosine distribution
• 3.27 Arcsine distribution
• 3.28 von Mises distribution
• 3.29 Non-Central Gammma distribution
• 3.30 Non-Central Beta distribution
• 3.31 Non-Central Chi-Square distribution
• 3.32 Non-Central Chi distribution
• 3.33 Non-Central F distribution
• 3.34 Non-Central t distribution
• 3.35 Planck distribution

### Discrete distributions

• Bernoulli distribution
• 4.1 Binomial distribution
• 4.2 Geometric distribution
• 4.3 Poisson distribution
• 4.4 Hypergeometric distribution
• 4.5 Multinomial distribution
• 4.6 Negative Binomial distribution
• 4.7 Negative Hypergeometric distribution
• 4.8 Logarithmic Series distribution
• 4.9 Yule-Simon distribution
• 4.10 Zipf-Mandelbrot distribution
• 4.11 Zeta distribution