Skip to content

Instantly share code, notes, and snippets.

@r3vit
Created September 8, 2016 12:07
Show Gist options
  • Save r3vit/d7890b0e0f18b53032cbb65050c72405 to your computer and use it in GitHub Desktop.
Save r3vit/d7890b0e0f18b53032cbb65050c72405 to your computer and use it in GitHub Desktop.
Simple random number generator Go
package main
import (
"fmt"
"math/rand"
"time"
)
//RandomNumber generate a random number from [min] to [max]
func RandomNumber(min, max int) int {
rand.Seed(time.Now().UnixNano())
return rand.Intn(max-min) + min
}
func main() {
//RandomNumber call from 1 to 100
rnd := RandomNumber(1, 100)
fmt.Println(rnd)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment