commit 943b758c5c73f754c2c23b079af157a1117a41a5 Author: Azathoth Date: Mon Aug 23 18:53:20 2021 +0200 Initial commit diff --git a/dice-roller b/dice-roller new file mode 100755 index 0000000..7194dc5 Binary files /dev/null and b/dice-roller differ diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..19fe50f --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.voidcruiser.nl/Azathoth/dice-roller + +go 1.17 diff --git a/main.go b/main.go new file mode 100644 index 0000000..c10bcc9 --- /dev/null +++ b/main.go @@ -0,0 +1,40 @@ +package main + +import ( + "flag" + "fmt" + "math/rand" + "time" +) + +func main() { + var surfaces, throws int + rand.Seed(time.Now().Unix()) + // fmt.Println("Half arsed version without error checking.") + // fmt.Println("Please insert number of die surfaces followed by amount of dice thrown.") + // fmt.Scanf("%d %d", &surfaces, &throws) + flag.IntVar(&surfaces, "s", 20, "Specify die type") + flag.IntVar(&throws, "t", 1, "Specify dice throws") + flag.Parse() + fmt.Println(surfaces) + fmt.Println(throws) + fmt.Println(Cast(surfaces, throws)) + +} + +func Cast(dieSurfaces, castAmount int) int { + fmt.Println(dieSurfaces) + fmt.Println(castAmount) + var ( + casts []int + cast, total int + ) + + for i := 0; i < castAmount; i++ { + cast = rand.Intn(dieSurfaces) + 1 + casts = append(casts, cast) + total += cast + } + fmt.Println(casts) + return total +}