Skip to content

Commit

Permalink
Merge pull request #216 from lunakv/dice-calculation-fix
Browse files Browse the repository at this point in the history
Fix dice rolling calculation
  • Loading branch information
Fryyyyy authored Nov 21, 2023
2 parents 73d05e3 + 22ea83c commit 45d991d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions dice.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ type Roll struct {

func (d Roll) calculate() string {
if d.sides == 0 {
return fmt.Sprintf("1 %d-sided die: %d", d.number, rand.Intn(d.number-1)+1)
return fmt.Sprintf("1 %d-sided die: %d", d.number, rand.Intn(d.number)+1)
}
var result int
for i := 1; i <= d.number; i++ {
result += rand.Intn(d.sides-1) + 1
result += rand.Intn(d.sides) + 1
}

if d.operand != 0 {
Expand Down

0 comments on commit 45d991d

Please sign in to comment.