Skip to content

Instantly share code, notes, and snippets.

@Fosome
Created March 24, 2014 16:15
Show Gist options
  • Save Fosome/9743516 to your computer and use it in GitHub Desktop.
Save Fosome/9743516 to your computer and use it in GitHub Desktop.
roll dice
// 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