How to Generate List of Unique Random Numbers in Python?

19-May-2023

.

Admin

How to Generate List of Unique Random Numbers in Python?

Hi Dev,

In this post, we will learn to create a list of numbers from unique random in a Python tutorial example. Here you will learn Python to create a list unique random of numbers. you will learn to create a list of numbers python unique random. This article goes into detail on how to create a list from unique random in Python. Follow the below tutorial step of Python to create a list of numbers from unique random.

If you are looking to generate a list of unique random numbers in Python, there are several ways to create a list of unique random numbers in Python. here, I will give you one example with the random library for creating new list unique random numbers in Python. so, let's see the example code.

Example :


main.py

import random

# python generate list of unique random numbers

myList = random.sample(range(1, 30), 10)

print(myList)

Output:

[12, 26, 17, 5, 18, 16, 8, 21, 24, 2]

#Python