- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Generate random numbers within a given range and store in a list
In this article we will see how to generate Random numbers between a pair of numbers and finally store those values into list.
We use a function called randint. First let's have a look at its syntax.
randint(start, end) Both start and end should be integers. Start should be less than end.
In this example we use the range function in a for lowith help of append we generate and add these random numbers to the new empty list.
import random def randinrange(start, end, n): res =  for j in range(n): res.append(random.randint(start, end)) return res # Number of random numbers needed n = 5 # Start value start = 12 #End value end = 23 print(randinrange(start, end, n))
Running the above code gives us the following result −
[21, 20, 20, 17, 20]
- Python program to generate random numbers within a given range and store in a list?
- Java program to generate random numbers within a given range and store in a list
- How can I generate random numbers in a given range in Android using Kotlin?
- Java Program to create random BigInteger within a given range
- Python – Random range in a List
- How to find Kaprekar numbers within a given range using Python?
- Python - Find the number of prime numbers within a given range of numbers
- Java Program to generate random number array within a range and get min and max value
- Python Program to replace list elements within a range with a given number
- How can I generate random number in a given range in Android?
- Golang Program to Print Odd Numbers Within a Given Range
- Generate pseudo-random numbers in Python
- How to generate random numbers with sequence and store in a data frame column in R?