Skip to main content

igraph_rng_t

Struct igraph_rng_t 

Source
pub struct igraph_rng_t { /* private fields */ }

Implementations§

Source§

impl igraph_rng_t

Source

pub fn new(kind: RngType, seed: u64) -> Result<Self>

Creates a new generator of the given type, seeded with seed (igraph_rng_init and igraph_rng_seed).

Two generators of the same type and seed produce the same numbers, on any thread:

use igraph::prelude::*;
// Pinned by igraph's own tests (`rng_init_destroy_max_bits_name_set_default.out`).
let mut mt = Rng::new(RngType::Mt19937, 42).unwrap();
let draws: Vec<i64> = (0..5).map(|_| mt.get_integer(0, 100)).collect();
assert_eq!(draws, vec![37, 80, 96, 18, 73]);
§Errors

ErrorKind::OutOfMemory if the state cannot be allocated.

Source

pub fn set_seed(&mut self, seed: u64) -> Result<()>

Re-seeds this generator (igraph_rng_seed): the numbers it produces afterwards depend only on its type and on seed.

Source

pub fn name(&self) -> String

The name of the algorithm, e.g. "MT19937", "LIBC", "PCG32" or "PCG64" (igraph_rng_name).

Source

pub fn get_integer(&mut self, min: i64, max: i64) -> i64

A uniform random integer in the closed interval [min, max] (igraph_rng_get_integer).

§Panics

If min > max.

Source

pub fn get_unif(&mut self, min: f64, max: f64) -> f64

A uniform random real in [min, max) (igraph_rng_get_unif).

§Panics

If a bound is not finite, max - min overflows, or min > max.

Source

pub fn get_unif01(&mut self) -> f64

A uniform random real in [0, 1) (igraph_rng_get_unif01).

Source

pub fn get_normal(&mut self, mean: f64, sd: f64) -> f64

A normally distributed random real with mean mean and standard deviation sd (igraph_rng_get_normal).

Source

pub fn get_bool(&mut self) -> bool

A random boolean (igraph_rng_get_bool).

Source

pub fn get_geom(&mut self, p: f64) -> f64

A geometric random number: the number of failures before the first success, with success probability p (igraph_rng_get_geom).

Source

pub fn get_binom(&mut self, n: i64, p: f64) -> f64

A binomial random number with n trials of probability p (igraph_rng_get_binom).

Source

pub fn get_exp(&mut self, rate: f64) -> f64

An exponential random number with the given rate (igraph_rng_get_exp).

Source

pub fn get_gamma(&mut self, shape: f64, scale: f64) -> f64

A gamma random number with the given shape and scale (igraph_rng_get_gamma).

Source

pub fn get_pois(&mut self, mean: f64) -> f64

A Poisson random number with the given mean (igraph_rng_get_pois).

Source

pub fn bits(&self) -> u32

Number of random bits produced at once by this generator (igraph_rng_bits).

Source

pub fn max(&self) -> u64

The largest integer this generator produces natively (igraph_rng_max).

Source

pub fn is_seeded(&self) -> bool

Whether the generator has been seeded (always true for generators created with Rng::new): the is_seeded flag that igraph_rng_seed sets, and that igraph_setup checks before seeding the default generator.

Source

pub fn scoped<R>(&mut self, f: impl FnOnce() -> R) -> R

Runs f with this generator installed as the thread’s default one (igraph_rng_set_default), restoring the previous default afterwards, even if f panics.

Every randomized igraph function called by f on this thread (and the free functions of this module) then draws from self; other threads are not affected.

use igraph::prelude::*;
let mut rng = Rng::new(RngType::Mt19937, 7).unwrap();
let x = rng.scoped(|| rng::integer(0, 1_000_000));
let mut again = Rng::new(RngType::Mt19937, 7).unwrap();
assert_eq!(again.scoped(|| rng::integer(0, 1_000_000)), x);
Source§

impl igraph_rng_t

Source

pub fn sample_sphere_surface( &mut self, dim: usize, n: usize, radius: f64, positive: bool, ) -> Result<Vec<Vec<f64>>>

Like sample_sphere_surface, drawing from this generator (igraph_rng_sample_sphere_surface).

use igraph::prelude::*;
let mut a = Rng::new(RngType::Pcg64, 5)?;
let mut b = Rng::new(RngType::Pcg64, 5)?;
assert_eq!(a.sample_sphere_surface(4, 3, 1.0, false)?, b.sample_sphere_surface(4, 3, 1.0, false)?);
Source

pub fn sample_sphere_volume( &mut self, dim: usize, n: usize, radius: f64, positive: bool, ) -> Result<Vec<Vec<f64>>>

Like sample_sphere_volume, drawing from this generator (igraph_rng_sample_sphere_volume).

Source

pub fn sample_dirichlet( &mut self, n: usize, alpha: &[f64], ) -> Result<Vec<Vec<f64>>>

Like sample_dirichlet, drawing from this generator (igraph_rng_sample_dirichlet).

Trait Implementations§

Source§

impl Debug for igraph_rng_t

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for igraph_rng_t

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for igraph_rng_t

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.