Basic-benchmark-experiment/Go/code_unoptimised/main.go

30 lines
501 B
Go
Raw Permalink Normal View History

2024-03-11 12:43:52 +02:00
package main
import (
"fmt"
"math/rand"
)
func main() {
var (
total_attempts int = 15_000_000
successes_amount int = 0
)
for i := 0; i < total_attempts; i++ {
var (
a int = rand.Intn(255)
b int = rand.Intn(255)
c int = rand.Intn(255)
)
if a+b+c > 300 {
successes_amount++
}
}
fmt.Printf("Iterations: %v\n", total_attempts)
fmt.Printf("Valid sums: %v\n", successes_amount)
fmt.Printf("Probability: %v\n", (float32(successes_amount) / float32(total_attempts)))
}