Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
265ca354a4 | |||
1a00e389db | |||
21c28577ea | |||
9fd049ca2a | |||
8973f4b0d0 | |||
f3faa5ff5c | |||
504688c1b1 | |||
b60c9c6c25 |
12
README.md
12
README.md
@ -1,3 +1,13 @@
|
||||
# roll
|
||||
|
||||
A simple die roller
|
||||
A simple die roller
|
||||
|
||||
Example Usage:
|
||||
Just roll a single d20
|
||||
|
||||
`roll`
|
||||
|
||||
|
||||
Roll 5 d20 7 times
|
||||
|
||||
`roll 5d20x7`
|
||||
|
5
main.go
5
main.go
@ -20,6 +20,9 @@ func main() {
|
||||
parm = os.Args[1] + "d" + os.Args[2]
|
||||
}
|
||||
}
|
||||
if strings.HasPrefix(parm, "d") {
|
||||
parm = "1" + parm
|
||||
}
|
||||
|
||||
r = rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
num, sides, times := parseParm(parm)
|
||||
@ -58,7 +61,7 @@ func parseParm(p string) (int, int, int) {
|
||||
func roll(num, sides int) int {
|
||||
ret := 0
|
||||
for ; num > 0; num-- {
|
||||
ret += r.Intn(sides)
|
||||
ret += r.Intn(sides) + 1
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user