fnmain(){let uniform =urandom::distr::Uniform::from(-1.0f64..1.0f64);letmut rand =urandom::new();// The number of samples we'll take
const N:usize=1_000_000;letmut count =0;for_in0..N {// Sample a point within the square with side 2.0
let x = rand.sample(&uniform);let y = rand.sample(&uniform);// Count how many samples fall within the unit circle
if(x * x + y * y).sqrt()<1.0{
count +=1;}}// The area of a circle is `PI r²` and the radius in our example is `1`.
// The area of a square is `side²` and the side in our example is `2`.
// We know the ratio of these two is equal to our estimate.
let ratio = count asf64/(N asf64);// Scale the area of the square by this ratio to get `PI`.
let pi =4.0* ratio;println!("PI is estimated as {pi}");}