Trait ndarray_rand::RandomExt [] [src]

pub trait RandomExt<S, D> where S: DataOwned, D: Dimension {
    fn random<IdS>(dim: D, distribution: IdS) -> ArrayBase<S, D> where IdS: IndependentSample<S::Elem>;
    fn random_using<IdS, R>(dim: D, distribution: IdS, rng: &mut R) -> ArrayBase<S, D> where IdS: IndependentSample<S::Elem>, R: Rng;
}

Constructors for n-dimensional arrays with random elements.

This trait extends ndarray’s ArrayBase and can not be implemented for other types.

The default Rng is a fast automatically seeded rng (currently rand::weak_rng).

Required Methods

fn random<IdS>(dim: D, distribution: IdS) -> ArrayBase<S, D> where IdS: IndependentSample<S::Elem>

Create an array with shape dim with elements drawn from distribution using the default rng.

Panics if the number of elements overflows usize.

extern crate rand;
extern crate ndarray;
extern crate ndarray_rand;

use rand::distributions::Range;
use ndarray::Array;
use ndarray_rand::RandomExt;

let a = Array::random((2, 5), Range::new(0., 10.));
println!("{:8.4}", a);
// Example Output:
// [[  8.6900,   6.9824,   3.8922,   6.5861,   2.4890],
//  [  0.0914,   5.5186,   5.8135,   5.2361,   3.1879]]

fn random_using<IdS, R>(dim: D, distribution: IdS, rng: &mut R) -> ArrayBase<S, D> where IdS: IndependentSample<S::Elem>, R: Rng

Create an array with shape dim with elements drawn from distribution, using a specific Rng rng.

Panics if the number of elements overflows usize.

Implementors