Exactly. We would remove that but we would need to switch between Math.ceil and Math.floor.
Math.ceil
Math.floor
Making a function more complex in order to make it simpler to do something the function does not do is not very sensible. :)
What if we just did something like this:
function d(sides, hasZero = false) { return hasZero ? Math.ceil(Math.random() * sides) : Math.floor(Math.random() * sides); }
If you want to generate integers in a range, you might as well just do that.
But the first thing to check are the requirements for this use case.
I believe that none of these dice include zero. :)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Exactly. We would remove that but we would need to switch between
Math.ceil
andMath.floor
.Making a function more complex in order to make it simpler to do something the function does not do is not very sensible. :)
What if we just did something like this:
If you want to generate integers in a range, you might as well just do that.
But the first thing to check are the requirements for this use case.
I believe that none of these dice include zero. :)