Historically, rot.js was adding several new methods to JavaScript primordial objects: Array, String, Number, Date, Object and Function. This behavior is now frowned upon, so some of the provided functionality is now moved to the dedicated ROT.Util namespace.
A more verbose explanation about how ROT.Util.format works is available on a dedicated string formatting page.
The built-in modulus operator (%) yields negative results for negative arguments. Number.prototype.mod is guaranteed to return a positive value.
A numeric value often needs to be clamped into a useful range: