diff --git a/src/ndim/nvec.rs b/src/ndim/nvec.rs index ee9403b1..abfda5bd 100644 --- a/src/ndim/nvec.rs +++ b/src/ndim/nvec.rs @@ -1,4 +1,5 @@ use core::vec::{map_zip, from_elem, map, all, all2}; +use core::rand::{Rand, Rng, RngUtil}; use core::num::{Zero, Algebraic}; use std::cmp::FuzzyEq; use traits::dim::Dim; @@ -93,6 +94,20 @@ impl> FuzzyEq for NVec { all2(self.at, other.at, |a, b| a.fuzzy_eq_eps(b, epsilon)) } } +impl Rand for NVec +{ + fn rand(rng: &R) -> NVec + { + let dim = Dim::dim::(); + let mut res : NVec = Zero::zero(); + + for uint::range(0u, dim) |i| + { res.at[i] = rng.gen() } + + res + } +} + impl ToStr for NVec { fn to_str(&self) -> ~str