Last active
July 8, 2016 21:14
-
-
Save lmas/c7662bbcdd3e54ae6041 to your computer and use it in GitHub Desktop.
Go Random - Utility functions for math/rand
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
// Return a random int between min and max. | |
func RandRange(min, max int) int { | |
return rand.Intn(max-min+1) + min | |
} | |
// Return a random float between 0.0 and max. | |
func RandRangeFloat(max float64) float64{ | |
return rand.Float64() * max | |
} | |
// Return a bool based on a random percent check against "chance". | |
func Prob(chance int) bool { | |
return RandRange(0, 100) <= chance | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment