774 shaares
10 private links
10 private links
4 results
tagged
math
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
From HN
Good, intuitive introduction to matrices. Next steps could be showing that there are infinitely many different matrix representations of a linear map (different from the polynomials) and they can be used for function spaces, too.
Visualized for better understanding
TL;DR how the current implementation of Math.random() is old and should be replaced