Try random.randrange:

from random import randrange
print(randrange(10))
Answer from kovshenin on Stack Overflow
🌐
Python documentation
docs.python.org › 3 › library › random.html
random — Generate pseudo-random numbers
February 23, 2026 - Print a random integer between 1 and N inclusive, using randint(). ... Print a random floating-point number between 0 and N inclusive, using uniform().
🌐
Data Science Discovery
discovery.cs.illinois.edu › learn › Simulation-and-Distributions › Random-Numbers-in-Python
Random Numbers in Python - Data Science Discovery
# To use any `random` functions, we must first `import random`:\nimport random\n \n# Randomly generates a number in the range 1-10, including the end points:\nrandom.randint(1, 10) ...
Discussions

Whats your preferred way of generating a random number, e.g. between 1 and 100 ?
random.randint(0, 100) More on reddit.com
🌐 r/learnpython
41
6
January 25, 2022
How to generate random integers (0-9) in Python? - TestMu AI Community
How to Generate Random Integers Between 0 and 9 in Python? How can I generate random integers between 0 and 9 (inclusive) in Python? For example, I want to get numbers like 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. Can you show me how to generate a random integer Python between 0 and 9? More on community.testmu.ai
🌐 community.testmu.ai
0
December 11, 2024
I made a code that outputs a list of 10 random numbers and below it reprints it in numerical order. Considering I started learning Python less than 1 week ago, I am pretty proud of myself.
Every great journey begins with a single step More on reddit.com
🌐 r/Python
29
94
December 3, 2022
Generate 10 random numbers between 0-100. No more than 3 in a sequence and no more than 4 in 10s, 20s, ..., 90s. - Python
Use lists for the counts The range 0-9, 10-19, 20-29, and so on can easily be mapped to the range 0,1,2,3,4... via integer division // in Python. This result can be used as index for the lists I mentioned in 1 - this way, you don't need a huge if-elif-else chain, in fact, you don't even need a single if. More on reddit.com
🌐 r/learnprogramming
8
3
December 23, 2022
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-randint-function
randint() Function in Python - GeeksforGeeks
March 20, 2026 - Explanation: random.randint(-5, -1) returns a random integer from -5 to -1, including both endpoints. Example 2: This program generates five random numbers between 1 and 100.
🌐
W3Schools
w3schools.com › python › gloss_python_random_number.asp
Python Random Number
Python does not have a random() function to make a random number, but Python has a built-in module called random that can be used to make random numbers: Import the random module, and display a random number between 1 and 9: import random print(random.randrange(1,10)) Try it Yourself » ·
🌐
iO Flood
ioflood.com › blog › randint-python
Using Python's randint for Random Number Generation
February 5, 2024 - The randint function is part of Python’s random module, and it’s used to generate a random integer within a specified range. Here’s a simple example: import random number = random.randint(1, 10) print(number) # Output: # (A random number ...
Find elsewhere
🌐
Hero Vired
herovired.com › learning-hub › blogs › random-number-generator-python
Random Number Generator Python between 1 and 10 | Hero Vired
April 23, 2024 - Here’s an example that demonstrates the usage of randomness in Python: ... import random # Generate a random number between 1 and 10 random_number = random.randint(1, 10) print("Random number:", random_number) # Generate a random floating-point ...
🌐
Vultr
docs.vultr.com › python › examples › generate-a-random-number
Python Program to Generate a Random Number | Vultr Docs
December 9, 2024 - Dive into the usage of the random ... a particular distribution. Import the random module. Use the randint function to generate a random integer within a specified range. ... This code generates a random integer between 1 and ...
🌐
DEV Community
dev.to › marcosomma › i-ran-500-more-agent-memory-experiments-the-real-problem-wasnt-recall-it-was-binding-24kc
I Ran 500 More Agent Memory Experiments. The Real Problem Wasn’t Recall. It Was Binding. - DEV Community
3 weeks ago - Zero. Not one single task out of 250 used the recalled skill. The model read the skill, evaluated it, and decided every single time that it wasn't helpful. And the semantic similarity between the abstract skill and the actual task was essentially random noise.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-generate-random-numbers-within-a-given-range-and-store-in-a-list
Generate random numbers within a given range and store in a list - Python - GeeksforGeeks
May 5, 2025 - import numpy as np no = 10 a = 10 # start b = 40 # end res = np.random.randint(a, b + 1, size=no).tolist() print(res) ... Explanation: randint() quickly generates 10 random numbers between 10 and 40 in one go.
🌐
GitHub
github.com › meta-pytorch › OpenEnv › blob › main › tutorial › 01-environments.md
OpenEnv/tutorial/01-environments.md at main · meta-pytorch/OpenEnv
import random print("🎲 " + "="*58 + " 🎲") print(" Number Guessing Game - The Simplest RL Example") print("🎲 " + "="*58 + " 🎲") # Environment setup target = random.randint(1, 10) guesses_left = 3 print(f"\n🎯 I'm thinking of a number ...
Author   meta-pytorch
🌐
RANDOM.ORG
random.org › integer-sets
RANDOM.ORG - Integer Set Generator
This page allows you to generate random sets of integers using true randomness, which for many purposes is better than the pseudo-random number algorithms typically used in computer programs.
🌐
Medium
medium.datadriveninvestor.com › play-with-random-number-generation-with-python-4bc93331084c
Random Number Generation with Python | by Amit Chauhan | DataDrivenInvestor
April 20, 2023 - To implement a random module in Python, have to simply apply it using the “import” command in Python. ... It is the most basic function using the random module, by default it will take a range from 0.0 to 1.0 and print the value in a ...
🌐
Matplotlib
matplotlib.org › stable › tutorials › pyplot.html
Pyplot tutorial — Matplotlib 3.10.9 documentation
import matplotlib.pyplot as plt plt.plot([1, 2, 3, 4]) plt.ylabel('some numbers') plt.show() You may be wondering why the x-axis ranges from 0-3 and the y-axis from 1-4. If you provide a single list or array to plot, matplotlib assumes it is a sequence of y values, and automatically generates the x values for you. Since python ranges start with 0, the default x vector has the same length as y but starts with 0; therefore, the x data are [0, 1, 2, 3].
🌐
Nature
nature.com › npj heritage science › articles › article
Three-stage progressive framework for Dongba ancient texts inpainting | npj Heritage Science
3 weeks ago - That scheme led to the weight values λ1 = 10, λadv = 10, λfm = 100, λhrf = 30 and λms−ssim = 5. We use these hyperparameters to train all models, except those described in the loss ablation study.
🌐
TestMu AI Community
community.testmu.ai › ask a question
How to generate random integers (0-9) in Python? - TestMu AI Community
December 11, 2024 - How to Generate Random Integers Between 0 and 9 in Python? How can I generate random integers between 0 and 9 (inclusive) in Python? For example, I want to get numbers like 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. Can you show m…