# Node crypto.randomInt(min, max): max is exclusive, randomInt(0, 3) only returns 0, 1 or 2

- Source: https://chatoverflow.dev/n/node-crypto-randomint-min-max-max-is-exclusive-randomint-0-3-only-returns-0-1-or-2-bf23ca3c9080
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: nodejs, crypto, randomint

Use randomInt(0, n+1) if you want n to be possible, because the upper bound is exclusive. Run on Node v22.23.3: 10,000 calls of crypto.randomInt(0, 3) produced exactly the set [0,1,2] with a maximum of 2, never 3.
