From 39707b42dc7d80eae741125fc8f8480f341c5763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Sat, 18 May 2013 15:03:54 +0000 Subject: [PATCH] Add rand for nvec. --- src/ndim/nvec.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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