dice-roller/main.go

38 lines
573 B
Go
Raw Normal View History

2021-08-23 18:53:20 +02:00
package main
import (
"flag"
"fmt"
"math/rand"
"time"
)
func main() {
var surfaces, throws int
rand.Seed(time.Now().Unix())
2021-08-23 23:19:01 +02:00
flag.IntVar(&surfaces, "s", 20, "Specify amount of die surfaces")
2021-08-23 18:53:20 +02:00
flag.IntVar(&throws, "t", 1, "Specify dice throws")
flag.Parse()
2021-08-23 23:19:01 +02:00
Cast(surfaces, throws)
2021-08-23 18:53:20 +02:00
}
2021-08-23 23:19:01 +02:00
func Cast(dieSurfaces, castAmount int) {
2021-08-23 18:53:20 +02:00
var (
casts []int
cast, total int
)
for i := 0; i < castAmount; i++ {
cast = rand.Intn(dieSurfaces) + 1
casts = append(casts, cast)
total += cast
}
2021-08-23 23:19:01 +02:00
if castAmount > 1 {
fmt.Println(casts)
}
fmt.Println(total)
2021-08-23 18:53:20 +02:00
}