Ch.16, Listing 16.4 onward: default getter implementation: shift range of random values by +1


Regarding the Fightable interface damageRoll property’s getter implementation:
To obtain random roll results for e.g. a six-sided dice, shouldn’t it be:

get() = (0 until diceCount).map { Random().nextInt(diceSides) + 1 }.sum()

instead of:

get() = (0 until diceCount).map { Random().nextInt(diceSides + 1) }.sum()

so that the range of values would be 1..6 instead of 0..6?


Correct, this would return 1…6.


You’re right - but you are neglecting to imagine a zero-sided die, something quite common in the world of NyetHack. (Thanks - I’ll add a note to our errata page.)


I knew it!! You guys at BigNerdRanch really are from another dimension (the 0th one, I assume?).