Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ 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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should probably be gen_uniform_f32 or somesuch, since there could as well be versions for f64, and all the integer types.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess one could make it polymorphic using num-traits..

self.gen()
}
}

/// Creates a shrinker with zero elements.
Expand Down Expand Up @@ -1583,4 +1588,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.);
}
}
}