Python Generate List of Unique Random Numbers Example

By Hardik Savani October 30, 2023 Category : Python

Hi Dev,

Here, I will show you how to work python generate list of unique random numbers. I’m going to show you about python list of unique random numbers. step by step explain python generate a list of random numbers. If you have a question about how to create list of unique random numbers in python then I will give a simple example with a solution.

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 examples with random library for creating new list unique random numbers in python. so, let's see the example code.

You can use these examples with python3 (Python 3) version.

let's see below a simple example with output:

Example 1:

main.py

import random
  
# python generate list of random numbers
myList = random.sample(range(1, 30), 10)
  
print(myList)

Output:

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

I hope it can help you...

Tags :
Shares