DEV Community

Discussion on: How do you do random?

Collapse
dmiracle profile image
Dylan Miracle

Typically don't people mean the set of numbers [0, 9] when they say they want a random int between 0 and 10? I would assume they want something out of 10 vs something out of 11

Collapse
krofdrakula profile image
Klemen Slavič

Well that is where your specification definition alarm bells should start ringing like crazy. We don't have a precise mathematical definition for ranges and sets like this in everyday language among lay folk, therefore you have to clarify what you mean. The example I gave above explicitly lays out the expectations, which the original text hadn't.

Technically speaking saying "between 0 and 10" could mean (0, 10), [0, 10], (0, 10] or [0, 10). In most conversations I've had, people tend to treat ranges as inclusive, so [0, 10] would probably be my best guess, but that's just anecdotal evidence on my part, and should always be checked.