Struct set_genome::GenomeRng[][src]

pub struct GenomeRng { /* fields omitted */ }

This struct serves as the randomness source for all operations.

Implementations

impl GenomeRng[src]

pub fn new(seed: u64, std_dev: f64, cap: f64) -> Self[src]

Creates a GenomeRng.

seed is specified for reproducibility of experiments. std_dev configures the standard deviation of the normal distribution from which the weight perturbations are sampled. cap specifies the upper and lower bound of values returned from GenomeRng::weight_perturbation.

use set_genome::GenomeRng;
let genome_rng = GenomeRng::new(42, 0.1, 1.0);

pub fn gamble(&mut self, chance: f64) -> bool[src]

Returns true chance percent of the time.

// a coin flip
if genome_rng.gamble(0.5) {
    println!("heads")
} else {
    println!("tails")
}

// the following always happens, gambling with 100% chance to succeed
assert!(genome_rng.gamble(1.0), "I should always win!");

pub fn weight_perturbation(&mut self, weight: f64) -> f64[src]

Returns the weight altered by some random value.

let mut genome_rng = GenomeRng::new(42, 0.1, 1.0);
// random_weight will probably be some small value,
// definitely not bigger than 1.0 or smaller than -1.0.
let random_weight = genome_rng.weight_perturbation(0.0);

Trait Implementations

impl Debug for GenomeRng[src]

impl RngCore for GenomeRng[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<R> Rng for R where
    R: RngCore + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,