October 2019
Intermediate to advanced
444 pages
10h 37m
English
In just a few steps, we will be working with different modules:
use rand::prelude::*;pub fn monte_carlo_pi(iterations: usize) -> f32 { let mut inside_circle = 0; for _ in 0..iterations { // generate two random coordinates between 0 and 1 let x: f32 = random::<f32>(); let y: f32 = random::<f32>(); // calculate the circular distance from 0, 0 if x.powi(2) + y.powi(2) <= 1_f32 { // if it's ...