From 4546b1ddac8224fcc2af6510f99188c333dab4af Mon Sep 17 00:00:00 2001 From: Audun Skaugen Date: Fri, 26 Mar 2021 16:05:59 +0100 Subject: [PATCH 1/2] Add Gen::gen_uniform --- src/arbitrary.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/arbitrary.rs b/src/arbitrary.rs index 92f893b..7e729e7 100644 --- a/src/arbitrary.rs +++ b/src/arbitrary.rs @@ -76,6 +76,10 @@ impl Gen { { self.rng.gen_range(range) } + + pub fn gen_uniform(&mut self) -> f32 { + self.gen() + } } /// Creates a shrinker with zero elements. @@ -1583,4 +1587,14 @@ mod test { ], ); } + + #[test] + fn gen_uniform() { + let mut g = Gen::new(10); + for _ in 0..100 { + let u = g.gen_uniform(); + assert!(u >= 0.); + assert!(u < 1.); + } + } } From 7c2fe46df9c04f384a6814cfdb2314ad801c431b Mon Sep 17 00:00:00 2001 From: Audun Skaugen Date: Fri, 26 Mar 2021 16:20:02 +0100 Subject: [PATCH 2/2] Documentation --- src/arbitrary.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/arbitrary.rs b/src/arbitrary.rs index 7e729e7..fba18ad 100644 --- a/src/arbitrary.rs +++ b/src/arbitrary.rs @@ -77,6 +77,7 @@ impl Gen { self.rng.gen_range(range) } + /// Create a random number uniformly distributed on the unit interval [0, 1) pub fn gen_uniform(&mut self) -> f32 { self.gen() }