Skip to content

"God does not play dice with the universe" β€” Albert Einstein

Disallow non-deterministic randomness (no-random) ​

πŸ’Ό This rule is enabled in the 🌐 all config.

πŸ”§ This rule is automatically fixable by the --fix CLI option.

πŸ“– Rule details ​

Code should be predictable. Replaces Math.random() with a deterministic value.

random

πŸ’‘ Examples ​

ts
// ❌ Incorrect
const foo = Math.random()

// βœ… Correct
const bar = 0.19891733174822845

πŸ”§ Config ​

js
{ rules: { 'ninja/no-random': 2 } }

πŸ”— See also ​

πŸ§‘β€πŸ’» Demo ​

Released under the MIT License