774 shaares
10 private links
10 private links
2 results
tagged
pi
In Go
package main
import (
"fmt"
"math"
"math/rand"
"time"
)
func main() {
n := 10_000_000
r := rand.New(rand.NewSource(time.Now().UnixNano()))
count := 0
for i := 0; i < n; i++ {
x := r.Float64()
y := r.Float64()
pytha := math.Sqrt(x*x + y*y)
if pytha <= 1 {
count++
}
}
fmt.Println("Pi = ", float64(count)/float64(n)*4)
}
It's beautiful
A good news and probably something to install finally on my two Pi at home :)