use bland::{Figure, Hatch, Normalize, PaperSize};
fn main() {
let samples: Vec<f64> = (0..2000)
.map(|i| {
let u1 = (i as f64 * 0.732 + 0.31) % 1.0;
let u1 = u1.max(1e-9);
let u2 = (i as f64 * 1.197 + 0.71) % 1.0;
(-2.0 * u1.ln()).sqrt() * (2.0 * std::f64::consts::PI * u2).cos()
})
.collect();
let fig = Figure::new()
.size(PaperSize::Letter)
.title("Standard normal — 2000 samples")
.xlabel("z")
.ylabel("density")
.histogram(&samples, |h| {
h.bins(40)
.normalize(Normalize::Density)
.hatch(Hatch::Diagonal)
.label("samples")
})
.legend_top_right();
std::fs::create_dir_all("out").expect("create out/");
std::fs::write("out/histogram.svg", fig.to_svg()).expect("write svg");
println!("wrote out/histogram.svg");
}