Skip to content

Instantly share code, notes, and snippets.

@nhooyr
Created January 25, 2016 22:53
Show Gist options
  • Save nhooyr/805c62370bfb3f3f6a95 to your computer and use it in GitHub Desktop.
Save nhooyr/805c62370bfb3f3f6a95 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math/rand"
"time"
)
const (
max = 100 + 1
tries = max * 100000
)
func main() {
rand.Seed(time.Now().UnixNano())
m := make(map[int]int)
for i := 0; i < tries; i++ {
j := rand.Intn(max)
m[j]++
}
for k, v := range m {
fmt.Printf("%5d: %f%%\n", k, float64(v)/tries*100)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment