-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmod.rs
More file actions
28 lines (26 loc) · 829 Bytes
/
mod.rs
File metadata and controls
28 lines (26 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//! Random number utilities used by examples and tests.
//!
//! Functions here delegate to the `rand` crate to generate simple random
//! values and uniformly distributed sequences.
use rand::Rng;
/// Generate a random float within any given range.
#[inline(always)]
pub fn get_random_float_between(min: f32, max: f32) -> f32 {
let mut rng = rand::thread_rng();
return rng.gen_range(min..max);
}
/// Generate a vector of uniformally distributed random floats within any given
/// range.
pub fn get_uniformly_random_floats_between(
min: f32,
max: f32,
count: usize,
) -> Vec<f32> {
let distribution = rand::distributions::Uniform::new(min, max);
let mut rng = rand::thread_rng();
let mut result = Vec::with_capacity(count);
for _ in 0..count {
result.push(rng.sample(distribution));
}
return result;
}