Created
September 8, 2016 12:07
-
-
Save r3vit/d7890b0e0f18b53032cbb65050c72405 to your computer and use it in GitHub Desktop.
Simple random number generator Go
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" | |
) | |
//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