spdkit_surface/
sample.rs

1// [[file:../spdkit-surface.note::1b57a2f8][1b57a2f8]]
2use rand::prelude::*;
3
4/// return random 2D fractional coords in xy surface
5///
6/// x,y: (0, 1]
7pub fn random_frac_xy() -> [f64; 2] {
8    let xdist = rand::distributions::Uniform::new(0.0, 1.0);
9    let ydist = rand::distributions::Uniform::new(0.0, 1.0);
10
11    let x: f64 = thread_rng().sample(xdist);
12    let y: f64 = thread_rng().sample(ydist);
13    [x, y]
14}
15
16/// return random 3D fractional coords in xyz space
17/// x,y: (0, 1]
18/// z: (zlow, zhigh)
19pub fn random_frac_xyz(zlow: f64, zhigh: f64) -> [f64; 3] {
20    let xdist = rand::distributions::Uniform::new(0.0, 1.0);
21    let ydist = rand::distributions::Uniform::new(0.0, 1.0);
22    let zdist = rand::distributions::Uniform::new(zlow, zhigh);
23
24    let x: f64 = thread_rng().sample(xdist);
25    let y: f64 = thread_rng().sample(ydist);
26    let z: f64 = thread_rng().sample(zdist);
27    [x, y, z]
28}
29// 1b57a2f8 ends here