Skip to content

Commit

Permalink
fix dice rolling calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
lunakv committed Nov 18, 2023
1 parent 4bc2b75 commit 22ea83c
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 22ea83c

Please sign in to comment.