Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
True or false output based on a probability
package main
import (
"time"
"fmt"
"math/rand"
)
func Decision(probability float64) bool {
// randFloat64() returns a float64, `0.0 <= f < 1.0`
return rand.Float64() <= probability
}
func main() {
rand.Seed(time.Now().UTC().UnixNano())
counts := make(map[bool]int)
for i:=0; i < 100000; i++ {
res := Decision(0.1)
counts[res]++
}
fmt.Println(counts)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.