From 46fa862e04bc43311ba79ef3db70abf9014b9104 Mon Sep 17 00:00:00 2001 From: tom barrett Date: Sun, 3 Feb 2019 05:45:35 -0600 Subject: bringing to 2018 --- src/math.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/math.rs') diff --git a/src/math.rs b/src/math.rs index 127d4b4..689ee65 100644 --- a/src/math.rs +++ b/src/math.rs @@ -1,11 +1,16 @@ extern crate rand; +use self::rand::distributions::Alphanumeric; use self::rand::Rng; +use std::iter::repeat; -pub fn distance(l0 : (f64, f64, f64), l1 : (f64, f64, f64)) -> f64 { - (((l1.0-l0.0).powf(2.0) + (l1.1-l0.1).powf(2.0) + (l1.2-l0.2).powf(2.0))).sqrt() +pub fn distance(l0: (f64, f64, f64), l1: (f64, f64, f64)) -> f64 { + ((l1.0 - l0.0).powf(2.0) + (l1.1 - l0.1).powf(2.0) + (l1.2 - l0.2).powf(2.0)).sqrt() } pub fn rand_name() -> String { - rand::thread_rng().gen_ascii_chars().take(8).collect() + repeat(()) + .map(|()| rand::thread_rng().sample(Alphanumeric)) + .take(8) + .collect() } -- cgit v1.2.3