Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesrandom.randint(a, b) in Python’s standard library includes both endpoints: a result can be a or b. NumPy’s similarly named functions differ: their upper bound is excluded by default. For a six-sided die, use random.randint(1, 6) in Python, but use np.random.randint(1, 7) or rng.integers(1, 7) with NumPy’s default settings.
Are both ends included in Python’s randint()?
Yes. Python’s standard-library random.randint(a, b) returns an integer N satisfying a <= N <= b. The Python 3.14.8 documentation describes it as an alias for randrange(a, b + 1) (Python documentation: random.randint).
For example, random.randint(1, 6) can return any integer from 1 through 6, including both 1 and 6. This differs from Python’s familiar range(start, stop) convention, where the stop value is excluded: randrange(start, stop, step) chooses from the corresponding range (Python documentation: random.randrange).
Why does NumPy randint() behave differently?
NumPy’s legacy np.random.randint(low, high) includes low but excludes high. Its possible results are in the half-open interval [low, high), so the largest result is high - 1 (NumPy documentation: numpy.random.randint).
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11#1 Best Overall
That means np.random.randint(1, 6) returns values from 1 through 5—not 6. A one-argument call has another easily missed detail: np.random.randint(5) means values from 0 through 4, because the interval is [0, 5).
How to generate integers from 1 through 6
Use the call that matches the API’s endpoint convention:
Rank #2
| API | Endpoint behavior | Call for values 1 through 6 |
|---|---|---|
random.randint(a, b) |
Includes both bounds | random.randint(1, 6) |
np.random.randint(low, high) |
Includes low; excludes high |
np.random.randint(1, 7) |
rng.integers(low, high) |
Includes low; excludes high by default |
rng.integers(1, 7) |
rng.integers(low, high, endpoint=True) |
Includes both bounds | rng.integers(1, 6, endpoint=True) |
For new NumPy code, create a generator with rng = np.random.default_rng() and call rng.integers(...). Its high argument is still exclusive by default; the endpoint=True option makes it inclusive (NumPy documentation: Generator.integers; NumPy beginner guide).
What to check when translating between APIs
- Check which library the function belongs to. The shared name
randintdoes not mean the bounds work the same way. - Check what the upper-bound argument represents. In Python’s standard library it is a possible result; in NumPy’s default calls it is the first value that cannot be returned.
- When translating an inclusive range to NumPy’s default API, add one to the upper bound. For example, Python’s 1-through-6 range becomes NumPy’s
(1, 7). - Use
endpoint=Truewhen you want NumPy’s upper argument to be included explicitly.
NumPy integer dtype note
NumPy’s randint default integer dtype depends on platform sizing; the reference notes that the default corresponds to np.intp sizing since NumPy 2.0. If your code requires a particular fixed-width integer type, specify dtype rather than relying on the platform default (NumPy documentation: numpy.random.randint).
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




