Created
January 25, 2016 22:53
-
-
Save nhooyr/805c62370bfb3f3f6a95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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