Skip to content

Instantly share code, notes, and snippets.

@lmas
Last active July 8, 2016 21:14
Show Gist options
  • Save lmas/c7662bbcdd3e54ae6041 to your computer and use it in GitHub Desktop.
Save lmas/c7662bbcdd3e54ae6041 to your computer and use it in GitHub Desktop.
Go Random - Utility functions for math/rand
// 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