Add rand for nvec.

This commit is contained in:
Sébastien Crozet 2013-05-18 15:03:54 +00:00
parent 622435f7ad
commit 39707b42dc
1 changed files with 15 additions and 0 deletions

View File

@ -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<D, T:FuzzyEq<T>> FuzzyEq<T> for NVec<D, T>
{ all2(self.at, other.at, |a, b| a.fuzzy_eq_eps(b, epsilon)) }
}
impl<D: Dim, T: Rand + Zero + Copy> Rand for NVec<D, T>
{
fn rand<R: Rng>(rng: &R) -> NVec<D, T>
{
let dim = Dim::dim::<D>();
let mut res : NVec<D, T> = Zero::zero();
for uint::range(0u, dim) |i|
{ res.at[i] = rng.gen() }
res
}
}
impl<D: Dim, T:ToStr> ToStr for NVec<D, T>
{
fn to_str(&self) -> ~str