Try random.randrange:

from random import randrange
print(randrange(10))
Answer from kovshenin on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_random_randrange.asp
Python Random randrange() Method
Python Examples Python Compiler ... Interview Q&A Python Bootcamp Python Training ... The randrange() method returns a randomly selected element from the specified range....
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ random.html
random โ€” Generate pseudo-random numbers
February 23, 2026 - The default random() returns multiples of 2โปโตยณ in the range 0.0 โ‰ค x < 1.0. All such numbers are evenly spaced and are exactly representable as Python floats. However, many other representable floats in that interval are not possible ...
Discussions

Python Rand+Range Question
Its just a convention python uses where all ranges are inclusive of the start value, but exclusive of the end value. It's the same as list indexing. my_list[3:5] will give you items 3 and 4 but not 5. More on reddit.com
๐ŸŒ r/learnprogramming
3
1
September 9, 2024
python - Generate random integers between 0 and 9 - Stack Overflow
I wanted only 10 rows (RANDOM_LIMIT) on trial run of 2,500 rows (row_count) so I used random_row_nos = [randint(1, row_count) for p in range(0, RANDOM_LIMIT)] based on this answer and it worked the first time! 2021-10-24T21:46:25.64Z+00:00 ... The secrets module is new in Python 3.6. More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to generate a range of random numbers in python without repetition - Stack Overflow
I would like to generate random numbers in the range (0..."MAX"). I would like to make a loop such that every time going through the loop a new unique random number is generated (should not repeat)... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - Generating random numbers in a specific range - Stack Overflow
-1 How do i put my random number into a specific range python More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ randrange-in-python
randrange() in Python - GeeksforGeeks
March 25, 2025 - The randrange() function in Python's random module is used to generate a random number within a specified range. It allows defining a start, stop, and an optional step value to control the selection of numbers.
Find elsewhere
๐ŸŒ
Python Morsels
pythonmorsels.com โ€บ random-numbers
Selecting random values in Python - Python Morsels
August 19, 2025 - The randrange function basically chooses a random number within a given range.
๐ŸŒ
Enki
enki.com โ€บ post โ€บ get-random-number-in-python
Enki | Blog - How to generate random numbers in Python
The ability to generate random numbers is a fundamental aspect in various domains of software development and data science. In this comprehensive guide, we will explore how to generate random numbers in Python using the random module. At Enki, we offer a wide range of tutorials to help you ...
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python โ€บ random module โ€บ .randrange()
Python | Random Module | .randrange() | Codecademy
March 9, 2022 - The .randrange() method selects a random number from a defined range of int values. ... Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
๐ŸŒ
Shiksha
shiksha.com โ€บ home โ€บ it & software โ€บ it & software articles โ€บ programming articles โ€บ how to generate random numbers in python?
How to Generate Random Numbers in Python? - Shiksha Online
September 6, 2024 - Then, we call the random() method to get a random float between 0-1 and store it in the variable n. Print the randomly generated number. ... randint() method to generate an integer number within a specified range.
๐ŸŒ
DEV Community
dev.to โ€บ hichem-mg โ€บ python-generate-random-integers-in-range-4m0d
Python: Generate Random Integers in Range - DEV Community
June 11, 2024 - import random # Generate a random integer between 50 and 100 (inclusive) random_int = random.randint(50, 100) print(random_int) # Generate a random integer between 10 and 20 (exclusive of 20) random_int = random.randrange(10, 20) print(random_int) ...
๐ŸŒ
Interactive Chaos
interactivechaos.com โ€บ en โ€บ python โ€บ function โ€บ randomrandrange
random.randrange | Interactive Chaos
February 23, 2021 - The random.randrange function returns a random element extracted from the sequence of integers generated by range (start, stop, step).
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ turtle.html
turtle โ€” Turtle graphics
February 23, 2026 - You can use the object-oriented approach in the shell, but it would be more typical in a Python script. The example above then becomes: from turtle import Turtle from random import random t = Turtle() for i in range(100): steps = int(random() * 100) angle = int(random() * 360) t.right(angle) t.fd(steps) t.screen.mainloop() Note the last line.
๐ŸŒ
GitHub
gist.github.com โ€บ karpathy โ€บ 8627fe009c40f57531cb18360106ce95
microgpt ยท GitHub
6 days ago - PostGPT is a zero-dependency BPE transformer that generates coherent text without a single gradient step. No PyTorch at runtime. No NumPy. Just math and random.
๐ŸŒ
scikit-learn
scikit-learn.org โ€บ stable โ€บ modules โ€บ generated โ€บ sklearn.ensemble.RandomForestClassifier.html
RandomForestClassifier โ€” scikit-learn 1.8.0 documentation
A random forest is a meta estimator that fits a number of decision tree classifiers on various sub-samples of the dataset and uses averaging to improve the predictive accuracy and control over-fitting. Trees in the forest use the best split strategy, i.e. equivalent to passing splitter="best" to the underlying DecisionTreeClassifier.