Created
March 24, 2014 16:15
-
-
Save Fosome/9743516 to your computer and use it in GitHub Desktop.
roll dice
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
// dice.go | |
package main | |
import ( | |
"fmt" | |
"flag" | |
"time" | |
"math/rand" | |
) | |
func main() { | |
sidesPtr := flag.Int("s", 6, "roll s sided die") | |
countPtr := flag.Int("n", 3, "roll n dice") | |
flag.Parse() | |
rand.Seed(time.Now().UnixNano()) | |
fmt.Println("Rolling", *countPtr, "dice...") | |
rolls := make([]int, *countPtr) | |
for i := 0; i < len(rolls); i++ { | |
rolls[i] = rand.Intn(*sidesPtr) + 1 | |
} | |
for i := range rolls { | |
fmt.Printf("%d ", rolls[i]) | |
} | |
fmt.Print("\n") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment