Generate random numbers in python?

Submitted 3 years, 8 months ago
Ticket #372
Views 445
Language/Framework Python
Priority Medium
Status Closed

Is there any way to generate random numbers in python?

If there is a way ,what is it?

How many are there to generate?

Thanks in advance.......

Submitted on Mar 10, 21
add a comment

2 Answers

Verified

You can use randint method.

Eg., import random #import random module

variable = random.randint(give the range here)

print(variable)

Hope this works

Submitted 3 years, 8 months ago


Verified

This is what Jaanvi is saying:

import random

# set a range ---
# I've set a range between 0 and 100
# since last value is exclusive
rand_value = random.randint(0, 101)

print(rand_value)

You can find more about random here: python docs - random (https://docs.python.org/3/library/random.html)

Submitted 3 years, 8 months ago


Latest Blogs