Ask coding questions

← Back to all posts
How do you generate random numbers in Python?
BOIBOI1

i just want to know...............................

Voters
jac1187
Vexcess
CateMeardon
SagaciousPan
BOIBOI1
Comments
hotnewtop
T11tu5

These two ways are my favourite:
from random import *
randint (1, 10)
and
import random
random.randint (1, 10)

christiant

The easiest method to do this is:

This simply chooses a random number between 1 and 10. You can change the two numbers to whatever you want just remember that the first number is the minimum and the second number is the maximum.

I hope this helped.

SagaciousPan

@BOIBOI1
The below code will print a random number between 1 and 100 ten times.

Test at:
https://repl.it/@SagaciousPan/Random-Number-Python

Hope I could help!

Please mark this as answered if your problem has been solved.

SixBeeps

https://docs.python.org/3/library/random.html
TL;DR, you can import the random library, and from there, call random.randrange(start, stop, step) to get a random number

mwilki7