pub struct Erlang { /* private fields */ }Expand description
Erlang Distribution
Represents a random variable following the Erlang distribution.
§Examples
// Create a new Erlang distribution with specified seeds
let mut erlang = rand_simple::Erlang::new([1192u32, 765u32, 1543u32]);
// Ensure the initial parameters are correctly set
assert_eq!(format!("{erlang}"), "Er(Shape parameter, Scale parameter) = Er(1, 1)");
// Generate a random number from the Erlang distribution
println!("Generating a random number following the standard Erlang distribution with shape parameter r = 1 and scale parameter θ = 1 -> {}", erlang.sample());
// Modify the parameters of the random variable
let shape: i64 = 2_i64;
let scale: f64 = 1.5_f64;
let result: Result<(i64, f64), &str> = erlang.try_set_params(shape, scale);
// Ensure the parameters are updated correctly
assert_eq!(format!("{erlang}"), "Er(Shape parameter, Scale parameter) = Er(2, 1.5)");
// Generate a random number from the modified Erlang distribution
println!("Generating a random number following the Erlang distribution with shape parameter r = {} and scale parameter θ = {} -> {}", shape, scale, erlang.sample());Implementations§
Source§impl Erlang
impl Erlang
Sourcepub fn new(seeds: [u32; 3]) -> Self
pub fn new(seeds: [u32; 3]) -> Self
Constructor
Creates a new instance of the Erlang distribution with the provided seeds for random number generation. Seeds are adjusted internally to ensure uniqueness.
§Arguments
seeds- Seeds for random number generation. Adjusted internally to ensure uniqueness.
§Returns
A new instance of the Erlang distribution.
§Example
// Create a new Erlang distribution with specified seeds
let mut erlang = rand_simple::Erlang::new([1192u32, 765u32, 1543u32]);Sourcepub fn sample(&mut self) -> f64
pub fn sample(&mut self) -> f64
Generate a random number.
This method calculates a random number using the standard gamma distribution.
§Returns
Returns a random number generated from the standard gamma distribution, multiplied by the scale parameter.
§Examples
let mut erlang = rand_simple::Erlang::new([1192u32, 765u32, 1543u32]);
let random_number = erlang.sample();
println!("Random number: {}", random_number);Sourcepub fn try_set_params(
&mut self,
shape: i64,
scale: f64,
) -> Result<(i64, f64), &str>
pub fn try_set_params( &mut self, shape: i64, scale: f64, ) -> Result<(i64, f64), &str>
Attempt to modify the parameters of the random variable.
shape- Shape parameter.scale- Scale parameter.
§Arguments
shape- Shape parameter.scale- Scale parameter.
§Returns
Returns a tuple (i64, f64) representing the modified parameters (shape, scale).
§Errors
Returns an error message if the provided parameters are invalid.
§Examples
let mut erlang = rand_simple::Erlang::new([1192u32, 765u32, 1543u32]);
assert_eq!(erlang.try_set_params(3, 0.5), Ok((3, 0.5)));
assert_eq!(erlang.try_set_params(0, 0.5), Err("The shape parameter is less than or equal to 0. The parameters of the random variable will remain unchanged."));
assert_eq!(erlang.try_set_params(1, -0.1), Err("The scale parameter is less than or equal to 0. The parameters of the random variable will remain unchanged."));Trait Implementations§
Auto Trait Implementations§
impl Freeze for Erlang
impl RefUnwindSafe for Erlang
impl Send for Erlang
impl Sync for Erlang
impl Unpin for Erlang
impl UnwindSafe for Erlang
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more